Delphi 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;

时间: 2024-12-28 12:07:38

Delphi GDI+ 学习记录(27): Bitmap的相关文章

Delphi GDI+ 学习记录(28): 图像颜色的数据格式

//指定位图颜色var g,gbit: TGPGraphics; bit1,bit2: TGPBitmap; sb: TGPSolidBrush; begin //Self.Color := clWhite; g := TGPGraphics.Create(Canvas.Handle); sb := TGPSolidBrush.Create(MakeColor(255,0,0)); {画刷为红色} bit1 := TGPBitmap.Create(200, 32, PixelFormat32bp

Delphi GDI+学习记录(21): 颜色

//颜色透明度var g: TGPGraphics; sb: TGPSolidBrush; begin g := TGPGraphics.Create(Canvas.Handle); sb := TGPSolidBrush.Create(MakeColor(128,255,0,0)); {128表示半透明} g.FillRectangle(sb,10,10,100,100); sb.Free; g.Free; end; //使用 GDI+ 的颜色类型var g: TGPGraphics; sb:

Delphi GDI+学习记录(19): 路径

//绘制与填充路径var g: TGPGraphics; path: TGPGraphicsPath; p: TGPPen; sb: TGPSolidBrush; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(128,255,0,0),4); sb := TGPSolidBrush.Create(MakeColor(128,255,255,0)); path := TGPGraphicsPat

Delphi GDI+学习记录(9): 纹理画刷

//纹理画刷 var g: TGPGraphics; img: TGPImage; tb: TGPTextureBrush; begin g := TGPGraphics.Create(Canvas.Handle); img := TGPImage.Create('c:\temp\small.jpg'); tb := TGPTextureBrush.Create(img); g.FillEllipse(tb, 0, 0, Self.ClientWidth, Self.ClientHeight);

Delphi GDI+学习记录(8): 阴影画刷

//阴影画刷 var g: TGPGraphics; hb: TGPHatchBrush; begin g := TGPGraphics.Create(Canvas.Handle); hb := TGPHatchBrush.Create(HatchStyleHorizontal, aclRed, aclYellow); {参数1是阴影样式; 参数2是前景色; 参数3是背景色, 参数3可选, 默认黑色} g.FillEllipse(hb, 11, 11, 222, 111); hb.Free; g

Delphi GDI+学习记录(4): 画笔对齐

//笔对齐 var g: TGPGraphics; p: TGPPen; sb: TGPSolidBrush; rect: TGPRect; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(255,255,0,0),5); sb := TGPSolidBrush.Create(MakeColor(255,255,255,0)); p.SetAlignment(PenAlignmentCenter

Delphi GDI+学习记录(3): 虚线画笔

//虚线样式 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(255,255,0,0),3); g.DrawLine(p, 11, 11, 333, 11); {实线} p.SetDashStyle(DashStyleDashDot); {设置虚线样式} g.DrawLine(p, 11, 33, 333, 33); {绘制任何形状都

Delphi GDI+学习记录(2): 画笔线帽

//线帽 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); p:= TGPPen.Create(aclBlue, 8); p.SetStartCap(LineCapArrowAnchor); {起点线帽} p.SetEndCap(LineCapRoundAnchor); {终点线帽} g.DrawLine(p, 20, 20, 300, 175); p.Free; g.Free; end; 线

Delphi GDI+ 学习记录(31): 图像颜色变换(TGPImageAttributes)

//正常显示图片, 没有变换uses GDIPAPI, GDIPOBJ; procedure TForm1.FormPaint(Sender: TObject); var g: TGPGraphics; img: TGPImage; begin g := TGPGraphics.Create(Canvas.Handle); img := TGPImage.Create('c:\temp\test.png'); {测试文件要存在} g.DrawImage(img, 0, 0, img.GetWid