Recent

Author Topic: [SOLVED]Draw Transparent Fill  (Read 10280 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED]Draw Transparent Fill
« on: April 27, 2019, 02:51:19 pm »
I am drawing on a BGRAControl canvas.

When I use "clNone" it is actually a white fill.

According to Class doc on WIKI white color is ued on Windows while WinNT is black.

How can I use an Alpha Transparent color of "0" opacity instead of white??

CODE
Code: Pascal  [Select][+][-]
  1.  
  2. paintbmp.Canvas.Brush.Color := clNone;
  3. paintbmp.Canvas.FloodFill(X, Y, clNone, fsSurface);
  4.  
  5.  
« Last Edit: April 28, 2019, 01:03:39 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

sstvmaster

  • Sr. Member
  • ****
  • Posts: 301
Re: Draw Transparent Fill
« Reply #1 on: April 27, 2019, 03:51:54 pm »
I had do this, i dropped a bgra Paintbox on the form. And then in the onPaint i have this:

Code: Pascal  [Select][+][-]
  1. ...
  2.  
  3.   // Hintergrund schwarz erzeugen - create black background
  4.   BGMask := TBGRABitmap.Create(632,392,clBlack);
  5.  
  6.   // Load background image
  7.   BGBitmap := TBGRABitmap.Create('images\World-Standard.bmp');
  8.  
  9.   // über Hintergrundbild eine transparente Farbe legen - Put a transparent color over the background picture
  10.   BGBitmap.FillRect(0,0,600,360,BGRA(43,14,177,240), dmDrawWithTransparency);
  11.   //                               ^ Color in RGB + Alpha
  12.  
  13. ...
  14.  
  15.   // Hintergrundbild, Gitter und Hintergrund vereinen - Merge
  16.   BGMask.PutImage(16,16,BGBitmap,dmDrawWithTransparency);
  17.  
  18. ...
  19.  
  20.   BGMask.Draw(pb_DrawSat.Canvas,0,0,True);
  21.  

greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Draw Transparent Fill
« Reply #2 on: April 27, 2019, 04:30:32 pm »
Without help (GR32, BGRA Bitmap, VampyreImagingLib, GDI+ etc.) it's not possible I think. The normal canvas is standard GDI, isn't it?
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Draw Transparent Fill
« Reply #3 on: April 27, 2019, 07:32:09 pm »
Without help (GR32, BGRA Bitmap, VampyreImagingLib, GDI+ etc.) it's not possible I think. The normal canvas is standard GDI, isn't it?

Note that he's using BGRABitmap ...
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6798
Re: Draw Transparent Fill
« Reply #4 on: April 27, 2019, 08:12:23 pm »
try setting the brush.style := bsClear;
The only true wisdom is knowing you know nothing

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw Transparent Fill
« Reply #5 on: April 27, 2019, 09:22:49 pm »
try setting the brush.style := bsClear;

"bsClear" still paints white.

paintbmp.Canvas.Brush.Style:=bsClear;
MyCanvas.Canvas.Brush.Style:=bsClear;

Tried that already

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw Transparent Fill
« Reply #6 on: April 27, 2019, 09:26:13 pm »
I had do this, i dropped a bgra Paintbox on the form. And then in the onPaint i have this:

Code: Pascal  [Select][+][-]
  1. ...
  2.  
  3.   // Hintergrund schwarz erzeugen - create black background
  4.   BGMask := TBGRABitmap.Create(632,392,clBlack);
  5.  
  6.   // Load background image
  7.   BGBitmap := TBGRABitmap.Create('images\World-Standard.bmp');
  8.  
  9.   // über Hintergrundbild eine transparente Farbe legen - Put a transparent color over the background picture
  10.   BGBitmap.FillRect(0,0,600,360,BGRA(43,14,177,240), dmDrawWithTransparency);
  11.   //                               ^ Color in RGB + Alpha
  12.  
  13. ...
  14.  
  15.   // Hintergrundbild, Gitter und Hintergrund vereinen - Merge
  16.   BGMask.PutImage(16,16,BGBitmap,dmDrawWithTransparency);
  17.  
  18. ...
  19.  
  20.   BGMask.Draw(pb_DrawSat.Canvas,0,0,True);
  21.  

This looks like inserting filling a RECT with a BMP with transparency

How does this help I I an creating a rectangle and I don't want the inside to be white??
Not understanding.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

sstvmaster

  • Sr. Member
  • ****
  • Posts: 301
Re: Draw Transparent Fill
« Reply #7 on: April 27, 2019, 10:07:50 pm »
Then i do not understand the problem. Can you make a example project?
greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: Draw Transparent Fill
« Reply #8 on: April 27, 2019, 10:55:33 pm »
Then i do not understand the problem. Can you make a example project?

Maybe i say is no problem ?

I am drawing on a BGRAControl canvas.

When I use "clNone" it is actually a white fill.

According to Class doc on WIKI white color is ued on Windows while WinNT is black.

How can I use an Alpha Transparent color of "0" opacity instead of white??

CODE
Code: Pascal  [Select][+][-]
  1.  
  2. paintbmp.Canvas.Brush.Color := clNone;
  3. paintbmp.Canvas.[u]FloodFill[/u](X, Y, clNone, fsSurface);
  4.  
  5.  
Floodfill alpha = no visible. Then no color paint. Is strange question i think ?

Maybe draw picture attach and see what want paint ?

add:

Oh... i maybe think i know. Want draw rectangle no inside ?
« Last Edit: April 27, 2019, 11:14:48 pm by Thausand »

lainz

  • Hero Member
  • *****
  • Posts: 4685
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Draw Transparent Fill
« Reply #9 on: April 27, 2019, 11:28:33 pm »
You mean TBGRAGraphicControl, it has on event OnRedraw, with the Bitmap property call Bitmap.FillTransparent.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap
  2.   );
  3. begin
  4.   Bitmap.FillTransparent;
  5. end;
  6.  

It MUST be TBGRAGraphicControl, is the only one that supports transparency.

And don't draw directly on control canvas, draw on Bitmap parameter!
« Last Edit: April 28, 2019, 12:08:10 am by Lainz »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw Transparent Fill
« Reply #10 on: April 28, 2019, 12:41:16 am »
Okay... making a "scratchpad" app. Got most of the code from LazPlanet

However, I am adding more features.

Yes, I am drawing Rect, Oval, Triangle with NO FILL

See screenshot
Red squares and numbering mark my reference.

If #1 (a checkbox) is checked, then draw fill, if unchecked NO FILL

No #2 shows a circle with a white fill. I want that to be NO Fill

So, the code I provided above earlier specifies clNone

CODE:
Code: Pascal  [Select][+][-]
  1. paintbmp.Canvas.Brush.Color := clNone;
  2. paintbmp.Canvas.FloodFill(X, Y, clNone, fsSurface);
  3.  

I ALSO TRIED: (but still paints white)

Code: Pascal  [Select][+][-]
  1.  
  2. paintbmp.Canvas.Brush.Style:=bsClear;
  3. MyCanvas.Canvas.Brush.Style:=bsClear;
  4.  
  5.  

However, as LAINZ mentioned, I may not be using the right BGRA Canvas control.

I am looking into it now

But here is the screen
You should get the idea.

I don't want a white fill, but I want none, so the square underneath shows through.
« Last Edit: April 28, 2019, 12:43:21 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4685
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Draw Transparent Fill
« Reply #11 on: April 28, 2019, 12:43:35 am »
What you are mixing is usage of BGRABitmap and normal canvas. There is no reason to do that.

Or use BGRABitmap or use normal canvas...

Code: Pascal  [Select][+][-]
  1. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap
  2.   );
  3. begin
  4.   Bitmap.FillTransparent;
  5.   Bitmap.Rectangle(10, 10, 100, 100, BGRABlack, BGRAPixelTransparent, dmDrawWithTransparency);
  6.   Bitmap.EllipseAntialias(100, 100, 50, 50, BGRABlack, 1, BGRAPixelTransparent);
  7. end;  

Or draw into a persistent Bitmap, then draw into the component.

MyBitmap: TBGRABitmap;

MyBitmap.Fill... // all drawing stuff into persistent Bitmap, anywhere in the code

Bitmap.PutImage(0, 0, MyBitmap, dmDrawWithTransparency); // OnRedraw event
« Last Edit: April 28, 2019, 12:54:56 am by Lainz »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw Transparent Fill
« Reply #12 on: April 28, 2019, 12:56:16 am »
I was using the PaintBox and not the BGRAGraphicControl, as LAINZ said.

Let me double-check that it works.
« Last Edit: April 28, 2019, 01:15:08 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw Transparent Fill
« Reply #13 on: April 28, 2019, 01:24:46 am »
LainZ, I going to go with the BGRA Graphic Control canvas.

Okay... the bsClear for Style works on the fill. Perfect!!!

What about the Pen, is there a "Clear" so I so don't draw a pen color or width if I leave my checkbox unchecked??


both of these don't work on the Pen.

Code: Pascal  [Select][+][-]
  1.  
  2. paintbmp.Canvas.Pen.Color:=clNone;
  3. MyCanvas.Canvas.Pen.Color:=clNone;
  4.  
  5. paintbmp.Canvas.Pen.Width:=0;
  6. MyCanvas.Canvas.Pen.Width:=0;
  7.  
  8.  

When Border/Stroke is unchecked I should be seeing NO PEN at all, but I still get thin black line.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Draw Transparent Fill
« Reply #14 on: April 28, 2019, 01:29:46 am »
stupid me, forgot to change the color to style
Looked up class, and found Style.psClear

Works perfect!!!

Code: Pascal  [Select][+][-]
  1.  
  2. paintbmp.Canvas.Pen.Style:=psClear;
  3. MyCanvas.Canvas.Pen.Style:=psClear;
  4.  
  5.  

THANKS ALL   :D

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018