![](https://i-blog.csdnimg.cn/blog_migrate/e3c3d4da1c312c2a56bdae9db7c253de.png)
//用 Bitmap 显示图像
var
g:TGPGraphics;
bit:TGPBitmap;
begin
g:=TGPGraphics.Create(Canvas.Handle);
g.Clear(aclWhite);
bit:=TGPBitmap.Create('d:\mm.jpg');
g.DrawImage(bit,11,11); {没有指定宽高,默认大小可能跟分辨率有关}
g.DrawImage(bit,250,11,bit.GetWidth,bit.GetHeight);{1:1}
g.DrawImage(bit,11,210,0.5*bit.GetWidth,0.5*bit.GetHeight);{2:1}
bit.Free;
g.Free;
end;
![](https://i-blog.csdnimg.cn/blog_migrate/03339ab0f6a0479f493d08a133a755aa.png)
//复制像素
var
g:TGPGraphics;
bit1,bit2:TGPBitmap;
pixh,pixw,width,height:Integer;
color:TGPColor;
begin
g:=TGPGraphics.Create(Canvas.Handle);
g.Clear(aclWhite);
bit1:=TGPBitmap.Create('d:\mm.jpg');
width:=bit1.GetWidth;
height:=bit1.GetHeight;
bit2:=TGPBitmap.Create(width,height);
for pixh := 0 to height - 1 do //纵向像素逐个复制
begin
for pixw := 0 to width - 1 do //横向像素逐个复制
begin
bit1.GetPixel(pixw,pixh,color);
bit2.SetPixel(pixw,pixh,color);
end;
end;
g.DrawImage(bit1,0,0,width,height);
g.DrawImage(bit2,width + 10,0,width,height);
bit1.Free;
bit2.Free;
g.Free;
![](https://i-blog.csdnimg.cn/blog_migrate/779ac4a0e05eb394b3be3baa1479f0b3.png)
//横向翻转
var
g:TGPGraphics;
bit1,bit2:TGPBitmap;
pixw,pixh,width,height:Integer;
color:TGPColor;
begin
g:=TGPGraphics.Create(Canvas.Handle);
g.Clear(aclWhite);
bit1:=TGPBitmap.Create('d:\mm.jpg');
width:=bit1.GetWidth;
height:=bit1.GetHeight;
bit2:=TGPBitmap.Create(width,height);
for pixh := 0 to height - 1 do
begin
for pixw := 0 to width - 1 do
begin
bit1.GetPixel(pixw,pixh,color);
bit2.SetPixel((width - 1) - pixw,pixh,color); {(width - 1) - pixw}
end;
end;
g.DrawImage(bit1,0,0,width,height);
g.DrawImage(bit2,width + 10,0,width,height);
bit1.Free;
bit2.Free;
g.Free;
end;
![](https://i-blog.csdnimg.cn/blog_migrate/f8307baeccfa6908d76d643610e0b30a.png)
//纵向翻转
var
g:TGPGraphics;
bit1,bit2:TGPBitmap;
pixw,pixh,width,height:Integer;
color:TGPColor;
begin
g:=TGPGraphics.Create(Canvas.Handle);
g.Clear(aclWhite);
bit1:=TGPBitmap.Create('d:\mm.jpg');
width:=bit1.GetWidth;
height:=bit1.GetHeight;
bit2:=TGPBitmap.Create(width,height);
for pixh := 0 to height - 1 do
begin
for pixw := 0 to width - 1 do
begin
bit1.GetPixel(pixw,pixh,color);
bit2.SetPixel(pixw,(height - 1) - pixh,color); {(height - 1) - pixh}
end;
end;
g.DrawImage(bit1,0,0,width,height);
g.DrawImage(bit2,width + 10,0,width,height);
bit1.Free;
bit2.Free;
g.Free;
end;
![](https://i-blog.csdnimg.cn/blog_migrate/3251b4be71b5e4fc353a8a221a7cac7f.png)
//透明度渐变
var
g:TGPGraphics;
bit1,bit2:TGPBitmap;
pixw,pixh,width,height:Integer;
color:TGPColor;
begin
g:=TGPGraphics.Create(Canvas.Handle);
g.Clear(aclWhite);
bit1:=TGPBitmap.Create('d:\mm.jpg');
width:=bit1.GetWidth;
height:=bit1.GetHeight;
bit2:=TGPBitmap.Create(width,height);
for pixh := 0 to height - 1 do
begin
for pixw := 0 to width - 1 do
begin
bit1.GetPixel(pixw,pixh,color);
color:=MakeColor(255*pixw div width,GetRed(color),GetGreen(color),GetBlue(color));
bit2.SetPixel(pixw,pixh,color);
end;
end;
g.DrawImage(bit1,0,0,width,height);
g.DrawImage(bit2,width + 10,0,width,height);
bit1.Free;
bit2.Free;
g.Free;
end;
![](https://i-blog.csdnimg.cn/blog_migrate/95a74d1fbc76d7b699c603f58d090dd1.png)
//显示 ico 图标
var
g:TGPGraphics;
bit:TGPBitmap;
ico:HICON;
begin
g:=TGPGraphics.Create(Canvas.Handle);
g.Clear(aclWhite);
ico:= LoadIcon(0,IDI_QUESTION);
bit:=TGPBitmap.Create(ico);
g.DrawImage(bit,10,10);
bit.Free;
g.Free;
end;