-3

I am using PNG images as main image resource in my application. Since im using Delphi 7, i downloaded PNGImage lib and included it in project. I load images like this:

Form.image.Picture.LoadFromFile(PAnsiChar('\background.png'));

Image has transparent and semi transparent pixels on its border. The problem i get is that transparent pixels are filled with random zoomed part of my desktop with currently opened windows, while i expected to see what is actually located beneath form.

Additionally, form has this properties:

BorderStyle: bsNone; TransparentColor: true; Visible: false;

Here is a picture of current state (above black line) and desired: delphi transparency issue

Can this be fixed somehow or it is how delphi deals with transparency?

13
  • 3
    Define "fixed". In other words, what do you want to appear under your image? And why are you setting TransparentColor and TransparentColorValue? And instead of telling us the version of Delphi that you are not using, could you tell us the version of Delphi that you are using? Apr 15, 2015 at 8:26
  • 3
    Actually your form settings read as: "For each black pixel of the form show the pixel of the underlying desktop or window." The result you are seeing seems to be just that. It is a bit unclear what you are trying to achieve.
    – Uwe Raabe
    Apr 15, 2015 at 8:48
  • @Uwe Raabe now i see how unclear my description is. Yes, transparent pixels show desktop, but what i see there is zoomed random part of desktop, not what actually placed beneath form
    – lolbas
    Apr 15, 2015 at 10:21
  • 1
    You still have not made any attempt to tell us what you want to achieve. You are asking us how to get from A to B without telling us what B is. Apr 15, 2015 at 10:36
  • @David Heffernan i want to see what is actually placed beneath form
    – lolbas
    Apr 15, 2015 at 11:12

1 Answer 1

1

To have the form "shade" what's beneath it, use the forms AlphaBlend and AlphaBlendValue properties. The .png image doesn't have to be partially (alpha blended) transparent, but it can be.


If you want the form to be semi-transparent you use Alphablending, that's a limitation of Windows. In addition you can have a certain color fully transparent. In the following sample the forms color is clGray, which is also defined as the Transparent color property in addition to the Transparent property set to True. The image, aligned alClient, is 50% transparent, placed on a TImage which is set as transparent, but even so, it doesn't show up as semi-transparent unless you have AlphaBlending on. Again, this is a limitation of Windows. The best you can do is try with a fairly high value for AlphaBlendingValue (240..250) and a rather light image to find the right compromise.

enter image description here

2
  • Im curious about image you have inserted. So you frame has this star as background image, right? And those triangles that left to make a rectangle seem to be transparent. Do they show what actually lays under form or you have same bug as i do?
    – lolbas
    Apr 15, 2015 at 19:48
  • The form is rectangular and the Color and TransparentColor properties are both the same clGray and the Transparent property is True. You can get hint about the forms edges from the vertical lines of the IDE seen behind on the left and right. On the form I have a TImage to which I have loaded the star image. The star image is a rectangular .png where the pixels surrounding the star are transparent. The buttons and the trackbar (to adjust Alphablend) were added at designtime. The form (or image) has no artifacts from the code behind, it's fully floating above the IDE behind. Apr 15, 2015 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.