Delphi 2007 - Loading TJvImage from a PNG file loses transparency

537 Views Asked by At

I have a couple of TJvImage components on my main form. One is loaded at design time from a partially transparent PNG file. The other is smaller than the first and in front of it. It is loaded at runtime with another partially transparent PNG file.

JvImage1.Picture.LoadFromFile ('Logo.png') ;  

JvImage1.Transparent is set to TRUE. The problem is simple: the smaller image is rendered ignoring the alpha channel - i.e. it punches out the background image.

This does not occur when I load both images at design-time. They both show as partially transparent on the form, and display correctly when I run the program.

The real dilemma is that a minimal test program written to try to demonstrate the problem does not show the problem, but the same code in the application proper doesn't behave.

Is there anything about the underlying main form that could affect the behaviour?

1

There are 1 best solutions below

0
On

I don't know if this is the same for TJvImage but when you set Transparent property of TImage to True it causes TImage to skip rendering any pixel with TransparentColor. If no transparent color is set the color of lower left pixel is used. When in such mode TImage doesen't take into accound alpha channel. Infact Transparency only works when you load TBitmap typed image into TImage.

I gues that TJvImage probably works in similar way. So in order to show your image properly you should set the Transparent property to False. This will probably alow TJvImage to render your picture by using Alpha transparency that is encoded to the picture itself.