* * *

Author Topic: Simple alpha transparent window  (Read 985 times)

Alloc

  • New member
  • *
  • Posts: 17
Simple alpha transparent window
« on: February 13, 2018, 02:24:20 pm »
Hi everyone,

we've got a small program that has a bunch of LCL windows that runs on Windows/macOs/Linux.

Now (for the Windows version only) we want to add one single window that should have an alpha transparent image as background. As for components we only need a progress bar and a button on that one.
As far as I'm aware the regular LCL windows don't allow alpha transparent backgrounds. I have looked around a bit regarding the different widgetsets but all documentation seemed to say that you use one of these widgetsets for the whole program.
So what would be the best way to get such a window in?

Kind regards,
Chris

howardpc

  • Hero Member
  • *****
  • Posts: 2715
Re: Simple alpha transparent window
« Reply #1 on: February 13, 2018, 02:31:47 pm »
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.  
  15.   public
  16.  
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. { TForm1 }
  27.  
  28. procedure TForm1.FormCreate(Sender: TObject);
  29. begin
  30.   AlphaBlend:=True;
  31.   AlphaBlendValue:=150;
  32. end;
  33.  
  34. end.

Alloc

  • New member
  • *
  • Posts: 17
Re: Simple alpha transparent window
« Reply #2 on: February 13, 2018, 02:42:36 pm »
But that would only make the window itself transparent, not use an alpha transparent image as background ;)
The important part here is really to have a custom PNG with alpha (of course could be converted to any other format if required) to be used as the background.

lainz

  • Hero Member
  • *****
  • Posts: 2816
    • Home
Re: Simple alpha transparent window
« Reply #3 on: February 13, 2018, 03:49:05 pm »
Check here:
https://github.com/lazarusccr/GraphicsContest/tree/master/2017/bgragraphics_by_j-g

Is a clock with a PNG with alpha (only Windows).

Alloc

  • New member
  • *
  • Posts: 17
Re: Simple alpha transparent window
« Reply #4 on: February 13, 2018, 08:03:08 pm »
Thanks lainz, that's kinda close :)

Had a look at that example and while it does allow for 1-bit Alpha it doesn't seem to really do alpha blending (as can also be seen in the screenshots in the example folder on the edges of the clock). It simply makes every pixel with A>0 white. Also toyed with the mode-argument of the PutImage method but that didn't seem to have any effect either.
It simply seems to blend the image against the window background color (clWhite by default but if you change to eg clRed you see it blends against red). Can that be changed somehow?

Chris

lainz

  • Hero Member
  • *****
  • Posts: 2816
    • Home
Re: Simple alpha transparent window
« Reply #5 on: February 13, 2018, 09:03:05 pm »
Thanks lainz, that's kinda close :)

Had a look at that example and while it does allow for 1-bit Alpha it doesn't seem to really do alpha blending (as can also be seen in the screenshots in the example folder on the edges of the clock). It simply makes every pixel with A>0 white. Also toyed with the mode-argument of the PutImage method but that didn't seem to have any effect either.
It simply seems to blend the image against the window background color (clWhite by default but if you change to eg clRed you see it blends against red). Can that be changed somehow?

Chris

Ask J-G, I help him some time ago to make the alpha transparency work fine, but I don't have the code, ask the code to him.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus