zoukankan      html  css  js  c++  java
  • GDI+ 学习记录(27): Bitmap

    //用 Bitmap 显示图像
    var
      g: TGPGraphics;
      bit: TGPBitmap;
    begin
      g := TGPGraphics.Create(Canvas.Handle);
      bit := TGPBitmap.Create('c:\temp\x.jpg');
    
      g.DrawImage(bit, 11, 11); {默认大小竟然和 1:1 不一样, 是不是分辨率的问题?}
      g.DrawImage(bit, 11, 11, bit.GetWidth, bit.GetHeight);         {1:1}
      g.DrawImage(bit, 11, 11, bit.GetWidth*0.5, bit.GetHeight*0.5); {1:2}
    
      bit.Free;
      g.Free;
    end;
    
    //复制像素 var g: TGPGraphics; bit1,bit2: TGPBitmap; row,column,width,height: Integer; color: TGPColor; begin g := TGPGraphics.Create(Canvas.Handle); bit1 := TGPBitmap.Create('c:\temp\x.jpg'); width := bit1.GetWidth; height := bit1.GetHeight; bit2 := TGPBitmap.Create(width, height); for row := 0 to height - 1 do begin for column := 0 to width - 1 do begin bit1.GetPixel(column, row, color); bit2.SetPixel(column, row, color); end; end; g.DrawImage(bit1, 0, 0, width, height); g.DrawImage(bit2, width, 0, width, height); bit1.Free; bit2.Free; g.Free; end;
    //横向翻转 var g: TGPGraphics; bit1,bit2: TGPBitmap; row,column,width,height: Integer; color: TGPColor; begin g := TGPGraphics.Create(Canvas.Handle); bit1 := TGPBitmap.Create('c:\temp\x.jpg'); width := bit1.GetWidth; height := bit1.GetHeight; bit2 := TGPBitmap.Create(width, height); for row := 0 to height - 1 do begin for column := 0 to width - 1 do begin bit1.GetPixel(column, row, color); bit2.SetPixel(width-column, row, color); {width-column} end; end; g.DrawImage(bit1, 0, 0, width, height); g.DrawImage(bit2, width, 0, width, height); bit1.Free; bit2.Free; g.Free; end;
    //纵向翻转 var g: TGPGraphics; bit1,bit2: TGPBitmap; row,column,width,height: Integer; color: TGPColor; begin g := TGPGraphics.Create(Canvas.Handle); bit1 := TGPBitmap.Create('c:\temp\x.jpg'); width := bit1.GetWidth; height := bit1.GetHeight; bit2 := TGPBitmap.Create(width, height); for row := 0 to height - 1 do begin for column := 0 to width - 1 do begin bit1.GetPixel(column, row, color); bit2.SetPixel(column, height-row, color); {height-row} end; end; g.DrawImage(bit1, 0, 0, width, height); g.DrawImage(bit2, width, 0, width, height); bit1.Free; bit2.Free; g.Free; end;
    //透明度渐变 var g: TGPGraphics; bit1,bit2: TGPBitmap; row,column,width,height: Integer; color: TGPColor; begin g := TGPGraphics.Create(Canvas.Handle); bit1 := TGPBitmap.Create('c:\temp\x.jpg'); width := bit1.GetWidth; height := bit1.GetHeight; bit2 := TGPBitmap.Create(width, height); for row := 0 to height - 1 do begin for column := 0 to width - 1 do begin bit1.GetPixel(column, row, color); color := MakeColor(255 * Column div width, GetRed(color), GetGreen(color), GetBlue(color)); bit2.SetPixel(column, row, color); end; end; g.DrawImage(bit1, 0, 0, width, height); g.DrawImage(bit2, width, 0, width, height); bit1.Free; bit2.Free; g.Free; end;
    //显示 ico 图标 var g : TGPGraphics; bit: TGPBitmap; ico: HICON; begin g := TGPGraphics.Create(Canvas.Handle); ico := LoadIcon(0, IDI_QUESTION); bit:= TGPBitmap.Create(ico); g.DrawImage(bit, 10, 10); bit.Free; g.Free; end;
  • 相关阅读:
    模板代码生成器 Template Code Creater
    Oracle编程入门经典 第2章 SQLPlus和基本查询
    Oracle编程入门经典 第5章 体系结构
    数据仓库
    C++ WINDOWS API 第1章 Windows 应用程序开发入门
    C++ WINDOWS API 第2章 Windows API概要
    Oracle编程入门经典 第7章 表
    单交换机VLAN虚拟局域网划分
    Oracle日志文件被误删除
    Oracle编程入门经典 第4章 新9i示例模式
  • 原文地址:https://www.cnblogs.com/del/p/1017608.html
Copyright © 2011-2022 走看看