• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

透明Png到TBitmap32

用户头像
it1352
帮助1

问题说明

我有一个png,我想加载一个TBitmap32。

I have a png that i would like to load in a TBitmap32.

加载位图后,我打电话:

After I load the bitmap I call:

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

但是所有的白色像素都是透明的。我该怎么做只是为了png图像的透明部分?这是我的图像,以标准方式指示图像边缘的Alpha透明度。

But then all white pixels are transparent. How can i do that just for the transparent part of the png image? Here is my image with the alpha transparency around the edge of the image indicated in the standard way.

这是实际的图片:

正确答案

#1

似乎 TBitmap32 可能会丢失 alpha 信息加载

It seems that TBitmap32 may lose alpha information while loading a PNG image.

您可以考虑使用 GR32_PNG单元,其中有一个文档摘录如下:

You may consider to use the GR32_PNG unit of which a documentation excerpt follows:


。 。 。
由于读写使用了一个中间的TBitmap对象,所以需要不必要的附加内存来存储位图数据。另外,通过将数据转换成TBitmap格式,也可以从附加信息转换数据,否则可能会丢失或处理错误。 。 。

要通过Graphics32本机处理PNG文件,可以使用第三方库GR32 PNG库。该库使用原生PNG格式作为中间存储。通过分配一个TBitmap32对象,数据可以在PNG上进行编码/解码。使用此库还可以访问存储在PNG文件中的其他信息。

. . .
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 Sourceforge下载页面

代码使用示例可以根据您的需要进行更改:

The code usage example of the unit can be changed as below to suit your needs:

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

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

其中位图是一个 TBitmap32 对象

生成的图像以 TImage32 组件:

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /reply/detail/tanhchaehg
系列文章
更多 icon
同类精品
更多 icon
继续加载