0

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?

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
rossmcm
  • 5,493
  • 10
  • 55
  • 118
  • 1
    I suggest you isolate the issue. Strip down the failing code until it works. Look at the dfm file. Why did set Transparent to True? Your image has an alpha channel. – David Heffernan May 22 '14 at 07:47
  • I never imagined you need to set `Transparent` to FALSE in order to get transparency to work. Now I know! (the help states: "Set Transparent to true to allow objects behind the TImage object to show through the background of the image. Set Transparent to false to make the background of the image opaque"). Unfortunately setting Transparent to false doesn't fix the problem. I tried creating a project and pasting the entire contents of the offending form into it, and the images display fine. I have a bit of work ahead of me. – rossmcm May 22 '14 at 21:24

1 Answers1

1

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.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22