delphi - 从鼠标光标下的像素获取 alpha channel 值

标签 delphi gdi+

如何使用 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/

相关文章:

delphi - 如何隐藏 TVirtualStringTree 节点?

.net - Region.IsVisible() 不按文档工作 (?) [GDI+]

c# - Windows/.NET 的 System.Drawing.Save(Stream, ImageFormat) 中的错误。生成损坏的 PNG

c# - 使用 DrawString 将单个字符居中

c++ - 如何使用 Libwebp 从 Webp 解码和编码?

c# - 以 PNG 格式保存图像时出现 GDI+ 异常

multithreading - 帖子线程消息 : Create a message queue

Delphi 2006 - 分配动态数组函数结果

delphi - Delphi XE下的DevExpress不起作用

delphi - 应用程序主题根据 Windows 主题而变化