透明Png到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
组件:
这篇好文章是转载于:编程之路
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 编程之路
- 本文地址: /reply/detail/tanhchaehg
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20