ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Draw Polygon to TIEBitmap w/ Alpha = 0?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Fellafoo Posted - Apr 04 2022 : 16:16:27
Is is possible to draw a polygon to a transparent bitmap?

For example:

ieBmp := TIEBitmap.Create(Width, Height, clBlack, 0);
ieCnv := TIECanvas.Create(ieBmp.Canvas);
ieCnv.Brush.Create(ieBrush);
ieCnv.Brush.Color := clYellow;
ieCnv.Brush.Transparency := 128;

To get a result, I must set the alpha to 255. I can set the alpha to 128 and the brush transparency to 255, but then the entire canvas has an alpha of 128. I want the non-filled areas to have an alpha of zero.
4   L A T E S T    R E P L I E S    (Newest First)
Fellafoo Posted - Apr 06 2022 : 10:27:41
I think my 'extra' canvas was the problem and with your new logic where I'm now drawing directly to the AlphaChannel canvas and calling AlphaChannel.Fill(0) at the beginning of each pass is working now. So thank you for that. ;-)
xequte Posted - Apr 05 2022 : 17:17:59
Hi

What problems are you having with it?

The AlphaChannel is itself just another TIEBitmap, so you can use all the same methods to reset it (allocating its size, filling, etc).

Nigel
Xequte Software
www.imageen.com
Fellafoo Posted - Apr 05 2022 : 16:37:58
Thanks Nigel,

Here's what I came up with...


procedure PolyPolygonForIE_Voids(aDC: HDC; aPtArr: PPoint; aPtCount: PInteger; aPlyCount: Integer; BrClr: TColor = 0; BrOp: Byte = 255; BmpBrush: Str255 = '');
{ Draw transparent polygons WITH voids using Windows PolyPolygon procedure & TIEBitmap AlphaChannel }
var
  TmpCnv: TCanvas;
  aBmp: TBitmap;
  ieBmp: TIEBitmap;

  DrawFormWidth, DrawFormHeight: Integer;

begin
  if (aPlyCount = 0) then Exit { Nothing to do }
  else if (aPtCount^ < 3) then Exit; { Not a valid polygon }

  { Create temporary canvas from Device Context }
  TmpCnv := TCanvas.Create;
  TmpCnv.Handle := aDC;
  DrawFormWidth := TmpCnv.ClipRect.Right;
  DrawFormHeight := TmpCnv.ClipRect.Top;

  { Create Bitmap for Alpha Channel (Mask) }
  aBmp := TBitmap.Create;
  aBmp.Canvas.Brush.Style := bsSolid;
  aBmp.Canvas.Brush.Color := clBlack; { Set color here before width / height }
  aBmp.Width := DrawFormWidth;
  aBmp.Height := DrawFormHeight;

  { Set brush color to grey value from user-defined opacity value }
  aBmp.Canvas.Brush.Color := RGB(BrOp, BrOp, BrOp);
  { Draw polygon with voids using Windows.PolyPolygon (Alpha Image) }
  PolyPolygon(aBmp.Canvas.Handle, aPtArr^, aPtCount^, aPlyCount);

  { Create 'ie' bitmap, same size as Device Context }
  ieBmp := TIEBitmap.Create(DrawFormWidth, DrawFormHeight, ie32RGB); { This method seems fastest }
  { Set compositing mode }
  ieBmp.IECanvas.SetCompositingMode(ieCompositingModeSourceOver, ieCompositingQualityDefault);

  { Assign Mask to ieBmp's Alpha Channel }
  ieBmp.AlphaChannel.Assign(aBmp);
  ieBmp.SyncAlphaChannel(True);

  { Set brush color to user-defined value }
  ieBmp.Canvas.Brush.Color := BrClr;
  { Draw polygon with voids using Windows.PolyPolygon (Source Image) }
  PolyPolygon(ieBmp.Canvas.Handle, aPtArr^, aPtCount^, aPlyCount);

  { Merge result onto our DrawForm canvas }
  ieBmp.DrawToCanvasWithAlpha(TmpCnv, 0, 0);

  aBmp.Free;
  ieBmp.Free;
  TmpCnv.Free;
end; { PolyPolygonForIE_Voids }


If I want to make ieBmp global and 'recycle' it, how do I go about reassigning the Alpha Channel? I've tried a few things, but I can't get the canvas / alpha channel to reset properly.
xequte Posted - Apr 04 2022 : 16:51:50
Hi

If the bitmap is transparent you are best to draw to both the bitmap and the alpha channel at the levels you want.

Another option is to create a ie32RGB bitmap, draw to the IECanvas and then synchronize the alpha channel (i.e. convert the A of RGBA to ImageEn's alpha channel).

https://www.imageen.com/help/TIEBitmap.SynchronizeRGBA.html

Nigel
Xequte Software
www.imageen.com