透明Png到TBitmap32 [英] Transparent Png to TBitmap32
问题描述
我有一个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.
这是实际的图片:
推荐答案
似乎 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.
代码使用示例可以根据您的需要进行更改:
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
组件:
这篇关于透明Png到TBitmap32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!