加载位图后,我调用:
Bitmap.DrawMode := dmTransparent; Bitmap.OuterColor := Bitmap.PixelS[0,0];
但是所有白色像素都是透明的.我怎么能只为png图像的透明部分做到这一点?这是我的图像,以标准方式指示图像边缘周围的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.
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组件中的形式加载: