首页 > Windows开发 > 详细

改变PNG图片的透明度 delphi

时间:2015-08-09 14:14:26      阅读:370      评论:0      收藏:0      [点我收藏+]
type
  TARGBRect = packed record
  Blue, Green, Red, Alpha: Byte; 
  end; 
var
  I, x, y: Integer; 
  bmp: TGpBitmap; 
  bg: TGpGraphics; 
  Data: TBitmapData; 
  P: PInteger; 
begin
  DoubleBuffered := True; 
  bmp := TGpBitmap.Create(‘0.bmp‘); 
  try
  Data := bmp.LockBits(GpRect(0, 0, W, H), [imRead, imWrite], pf32bppARGB); 
  P := Data.Scan0; 
  for y := 1 to Data.Height do
  for x := 1 to Data.Width do
  begin
  // 计算不透明度 
  with TARGBRect(P^) do
  Alpha := Max(Red, Max(Green, Blue)); 
  //Alpha := (Red + Green + Blue) div 3; 
  //Alpha := (306 * Red + 601 * Green + 117 * Blue) div 1024; 
  Inc(P); 
  end; 
  bmp.UnlockBits(Data); 
  bg := TGpGraphics.Create(form1.Canvas.Handle); 
  bg.DrawImage(bmp, 0, 0, bmp.wideh, bmp.Height); 
  end; 
  finally
  bg.Free; 
  bmp.Free; 
  end; 
end;

改变PNG图片的透明度 delphi

原文:http://my.oschina.net/u/1777508/blog/489749

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!