改變PNG圖片的透明度 delphi


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;  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM