加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – TBitmap32的透明Png

发布时间:2020-12-15 10:06:37 所属栏目:大数据 来源:网络整理
导读:我有一个png,我想在TBitmap32中加载. 加载位图后,我调用: Bitmap.DrawMode := dmTransparent;Bitmap.OuterColor := Bitmap.PixelS[0,0]; 但是所有白色像素都是透明的.我怎么能只为png图像的透明部分做到这一点?这是我的图像,以标准方式指示图像边缘周围的A
我有一个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组件中的形式加载:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读