delphi – TBitmap32的透明Png

前端之家收集整理的这篇文章主要介绍了delphi – TBitmap32的透明Png前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个png,我想在TBitmap32中加载.

加载位图后,我调用

Bitmap.DrawMode   := dmTransparent;
Bitmap.OuterColor := Bitmap.PixelS[0,0];

但是所有白色像素都是透明的.我怎么能只为png图像的透明部分做到这一点?这是我的图像,以标准方式指示图像边缘周围的Alpha透明度.

这是实际的图像:

解决方法

在加载PNG图像时,似乎TBitmap32可能会丢失alpha信息.

您可以考虑使用文档摘录如下的GR32PNG library

. . .
since reading and writing utilizes an intermediate TBitmap object,unnecessary additional memory is required to store the bitmap data. Also by converting data to and from the TBitmap format additional information might get lost or handled wrong.
. . .
To handle PNG files natively by Graphics32 the thirdparty library GR32 PNG Library can be used. This library use the native PNG format as intermediate storage. By assigning a TBitmap32 object the data is encoded/decoded to/from PNG on the fly. Using this library it is also possible to access additional information,which is stored in the PNG file.

Graphics32 project page

可以根据您的需要更改单元的代码用法示例:

var
  AlphaChannelUsed: Boolean;
begin
  LoadBitmap32FromPNG(Bitmap,<your path to the PNG image>,AlphaChannelUsed);

  if AlphaChannelUsed then
    Bitmap.DrawMode := dmBlend
  else
    Bitmap.DrawMode := dmOpaque;
end;

其中Bitmap是TBitmap32对象.

生成的图像以TImage32组件中的形式加载:

原文链接:https://www.f2er.com/delphi/103002.html

猜你在找的Delphi相关文章