如何使用 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;
最佳答案
问题是显示器上的图像没有透明度。
从根本上讲,您在显示器上看到的每个像素都没有透明度。
即想象一下点击 Print Scrn,并将桌面的副本粘贴到“画图”中。您不会找到任何部分透明的像素,因为根本不存在。至少您会看到壁纸的像素。
对于给您带来的不便,我们深表歉意。
关于delphi - 从鼠标光标下的像素获取 alpha channel 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10129594/