Recent

Author Topic: AlphaBlend := True ?  (Read 16809 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
AlphaBlend := True ?
« on: April 09, 2011, 02:31:38 am »
Hello everybody.
I try to have a transparent form.
Code: [Select]
Form1.AlphaBlendValue := 100; // 0..255
Form1.AlphaBlend := True;

Quote
Error:identifier idents no member "AlphaBlend"

I use FPC 2.4.0 in Linux, is it not yet implemented in that version ?

Thanks
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #1 on: April 09, 2011, 03:38:02 am »
Re-hello.

In a topic i find :

Quote
If you need only some parts transparent then use: TWinControl.SetShape(AShape: TBitmap).

It is exactly what i want.
But how must i do ?
I have image1 with transparent background.
What must be the code if i only want to see the image, without any background.  %)

Many thanks
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

jw

  • Full Member
  • ***
  • Posts: 126
Re: AlphaBlend := True ?
« Reply #2 on: April 09, 2011, 03:49:15 am »
see
C:\lazarus\examples\shapedcontrols

with this you can make a black and white bitmap as a mask for the shape of your control or form.


search transparent froms for a windows only api to set the form transparent by color

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #3 on: April 09, 2011, 02:24:59 pm »
@ jw Thanks, the result is exactly what i want but...
The example do not show how to convert a black and  white bitmap into a shape... :-\
How must i do ?
I have 2 images :

- a black and white image1.png (the future shape)
- a other image2.bmp (same shape that black and white image but with colors).

 and then ????
Thanks
« Last Edit: April 09, 2011, 02:52:57 pm by fredvs »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: AlphaBlend := True ?
« Reply #4 on: April 09, 2011, 05:30:02 pm »
Load the black and white picture into TBitmap and use TWinControl.SetShape ?

You may have to save the png into bmp for easier loading.

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #5 on: April 09, 2011, 10:19:58 pm »
OK User137, thanks,  :P its done (but with png image the program crash, with bmp image, no problem... see picture in attach).

Now i have a other question :
Is it possible to load a picture from  Timage into Tbitmap ?

Many thanks.
« Last Edit: April 09, 2011, 10:23:21 pm by fredvs »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: AlphaBlend := True ?
« Reply #6 on: April 10, 2011, 10:32:46 am »
Yes it is:

With tmpbmp declared as TBitmap,
and Image1 your TImage.
Code: Pascal  [Select][+][-]
  1.   tmpbmp := Graphics.TBitmap.Create;
  2.   tmpbmp:= Image1.Picture.Bitmap;
  3.  
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #7 on: April 10, 2011, 05:07:13 pm »
Yep FabienWang it does the think  ;D
And big thanks because it opens me a new world.
Normally i stored bitmap into resource, then load it from resource,... lot of work.  :-X
Now i only have to add a image, load picture as you said. And of course image.picture is stored in resource.  ::)
Many, many thanks.


 
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: AlphaBlend := True ?
« Reply #8 on: April 10, 2011, 05:54:55 pm »
may i ask you something about the black and white BMP ?
is it 8 bits or something?

Here is my code and it doesn't work:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   tmpbmp: TBitmap;
  4. begin
  5.   tmpbmp := TBitmap.Create;
  6.   tmpbmp.Monochrome := True;
  7.   tmpbmp.LoadFromFile('logoa.bmp');
  8.   self.SetShape(tmpbmp);
  9. end;

or it's not working on GTK2 ?
« Last Edit: April 10, 2011, 05:59:37 pm by FabienWang »
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #9 on: April 11, 2011, 12:04:29 pm »
 @Fabian...
Hum, this night i try to use your image.picture > bitmap method :

Code: [Select]
procedure TMiXimumSP.ShapeControl(AControl: TWinControl);
var
  ABitmap: TBitmap;
begin

 ABitmap := Graphics.TBitmap.Create;
 ABitmap := Image2.Picture.Bitmap;  
 
  ABitmap.Monochrome := True;
 ABitmap.Width := form1.Width;
   ABitmap.Height := form1.Height;

  AControl.SetShape(ABitmap);

 end;                  

It is working for Windows but in Linux it crashs... :(

So, im back to the old method...

Code: [Select]
procedure TMiXimumSP.ShapeControl(AControl: TWinControl);
var
  ABitmap: TBitmap;
  opaths:=strings  ;    

begin
 opaths := Application.Location  ;    
 ABitmap := Graphics.TBitmap.Create;
 {$IFDEF Windows}
 ABitmap.LoadFromFile(opaths +'lib\splash.bmp');
   {$ENDIF}
{$IFDEF UNIX}
  {$IFDEF Darwin}
   ABitmap.LoadFromFile(opaths +'/miximum.app/contents/macos/splash.bmp');

     {$ELSE}

 ABitmap.LoadFromFile(opaths +'/lib/splash.bmp');

      {$ENDIF}
     {$ENDIF}

  ABitmap.Monochrome := True;
 ABitmap.Width := form1.Width;
   ABitmap.Height := form1.Height;

  AControl.SetShape(ABitmap);

  ABitmap.Free;

end;                  

With that code, it is working for all systems...  ;D
« Last Edit: April 11, 2011, 12:17:57 pm by fredvs »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #10 on: April 11, 2011, 12:13:37 pm »
Re-@Fabian.

It seems to have a bug in image.picture in Linux.
When you load a monochrome picture in Linux, it crash...

That do not appear in Windows.

If you load a monochrome picture in Windows and when you use that same code in Linux, even Lazarus do not load, it crashs even Lazarus.... :(
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4715
  • I like bugs.
Re: AlphaBlend := True ?
« Reply #11 on: April 11, 2011, 01:52:03 pm »
It seems to have a bug in image.picture in Linux.
When you load a monochrome picture in Linux, it crash...

That do not appear in Windows.
If you load a monochrome picture in Windows and when you use that same code in Linux, even Lazarus do not load, it crashs even Lazarus.... :(

Could you please create a bug-report with a reproducible test application.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Fred vS

  • Hero Member
  • *****
  • Posts: 3946
    • StrumPract is the musicians best friend
Re: AlphaBlend := True ?
« Reply #12 on: April 11, 2011, 02:11:47 pm »
Other bemol for  AControl.SetShape(ABitmap).
It seems that it does not work with Mac OSX carbon (the form is normal, not shaped...).  :'(

The good news is that it works perfectly with Linux and Windows... ;D
« Last Edit: April 11, 2011, 02:14:40 pm by fredvs »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018