Delphi 2006: PNG runtime before TImage loses alpha transparency

Delphi 2006 TImage does not support PNG. In order to have images with alpha transparency in my forms, I have to upload them at runtime. I can load them during development, but they do not survive, I think, because PNGs are not saved in the DFM file. I am sure that this is all the hunky-dory in the latest Delphi, but I can’t upgrade right now.

Anyway, I loaded them at runtime:

Image1.Picture.Assign (PngImageCollection1.Items [0].PNGImage) ;

The PNGImageCollection component stores all my PNGs of different sizes (they are created and loaded during development), and I assign them to the corresponding TImages in the FormCreate event.

This worked fine until I had a problem when I tried to reuse one of these images in another place after it was used on the form. I found that the TPicture assignment action set it to an empty image as a result of Assign. This happened in TPicture.ForceType mode, which AFAICT checks the FGraphic type, and if it is not the desired type, it frees FGraphic and creates a new instance of the requested type.

OK Therefore, having scratched a little, I see that, perhaps, I really should do this:

Image1.Picture.Bitmap.Assign (PngImageCollection1.Items [0].PNGImage) ; 

This resulted in Assign not knocking the image, but the image now shows that the translucent bits are opaque, i.e.:

TImage when assigned with Image1.Picture.Bitmap.Assign

instead:

TImage when assigned with Image1.Picture.Assign

, - ? ( : Is Image1.Picture.Bitmap.Assign ?).

:

, " " TImage, :
:

LogoImage.Picture.Assign (PngImageCollection1.Items [0].PNGImage) ; 

(PNGIMage - , LogoImage1 ).

:

procedure PrintLogo (Report : TBaseReport) ;

var
    X1, Y1, LogoHeightMM    : Double ;

begin
with Report do
    begin
    LogoHeightMM  := CalcGraphicHeight (LogoWidthMM, MainForm.LogoImage.Picture.Graphic) ;
    X1            := PageWidth - MarginRight - LogoWidthMM ;
    Y1            := SectionBottom - LogoHeightMM ;
    PrintBitmapRect (X1, Y1, X1 + LogoWidthMM, Y1 + LogoHeightMM, MainForm.LogoImage.Picture.Bitmap) ;
    end ;
end ;

, LogoImage.Picture PrintBitmapRect. , , CalcGraphicHeight , .

. .Bitmap.Assign RTE , "" , PNG (, ), aplha .

+5
1

: , .

TImage TPngObject, png. , . , ,

  Bmp.Assign(Image1.Picture.Bitmap);

Image1 , png-, . ,

  Bmp.Assign(Image1.Picture.Graphic);

Image1 , png .

Delphi ( , ) -, Image1.Picture.Bitmap.Assign(.. .


, , , png .

+5

All Articles