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;

 
 
 
 
 

 

 

  

转载于:https://my.oschina.net/hermer/blog/320109

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值