如何使用 Delphi 2010 使用 GDIPlus 从 TImage 中鼠标光标下的像素获取 alpha 值?
我试过了,但 A 总是 255?我做错了什么?
procedure TFormMain.Image1MouseMove ( Sender: TObject; Shift: TShiftState; X, Y: Integer );
var
GPBitmap: TGPBitmap;
iColorRef: Cardinal;
iColor: TColor;
A, R, G, B: Byte;
iARGB: ARGB;
begin
if Assigned ( Image1.Picture ) then
begin
GPBitmap := TGPBitmap.Create ( Image1.Picture.Bitmap.Handle );
try
// Get alpha 0-255 from GPBitmap
GPBitmap.GetPixel ( X, Y, iColorRef );
iARGB := ColorRefToARGB ( iColorRef );
A := GetAlpha ( iARGB );
AlphaUnderCursor1.Caption := 'Alpha: ' + IntToStr ( A );
iColor := Image1.Canvas.Pixels [ X, Y ];
GetRGB ( iColor, R, G, B );
Shape1.Brush.Color := iColor;
finally
GPBitmap.Free;
end;
end;