Transparent Png to TBitmap32

前端 未结 2 1576
醉话见心
醉话见心 2020-12-10 19:22

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 := Bitma         


        
2条回答
  •  死守一世寂寞
    2020-12-10 20:02

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

    You may consider to use the GR32PNG library of which a documentation excerpt follows:

    . . .
    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


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

    var
      AlphaChannelUsed: Boolean;
    begin
      LoadBitmap32FromPNG(Bitmap, , AlphaChannelUsed);
    
      if AlphaChannelUsed then
        Bitmap.DrawMode := dmBlend
      else
        Bitmap.DrawMode := dmOpaque;
    end;
    

    Where Bitmap is a TBitmap32 object.


    The resulting image loaded in a form within a TImage32 component:

    enter image description here

提交回复
热议问题