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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Transparent drawing to TCanvas
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

HeartWare

Denmark
50 Posts

Posted - Feb 22 2018 :  09:22:18  Show Profile  Reply
How do you draw a TIEBitmap with AlphaChannel to a TCanvas?

IEBitmap.DrawToCanvas(Canvas,X,Y) doesn't seep to obey the transparency in the IEBitmap.

The IEBitmap was loaded from a disk file (.PNG with transparency) and if I save it back to another .PNG file, I can see that the transparency was preserved in the IEBitmap (also, AlphaChannel returns TRUE).

But if I use DrawToCanvas it doesn't appear to work.

I have attached the .PNG file, in case it is needed...



Also, a screen dump of the image drawn on a TGraphic's TCanvas with a Yellow background color:


w2m

USA
1990 Posts

Posted - Feb 22 2018 :  11:29:58  Show Profile  Reply
TIEBitmap.DrawToCanvasWithAlpha

Declaration

procedure DrawToCanvasWithAlpha(DestCanvas: TCanvas; xDst, yDst : integer; Transparency: integer; Opacity: double);

Description

Draws the whole bitmap to the specified DestCanvas canvas, at coordinates xDst, yDst with parameters:
Transparency specifies the transparency value (0 to 255).
Opacity specifies the opacity (0 to 1.0).

This functions reads the destination canvas pixels and merges them with image using the alpha channel mask.

Note: This is a simplified version of RenderToCanvasWithAlpha

Opacity vs Transparency

Both the Opacity and Transparency parameters provide the same functionality. Transparency is the traditional ImageEn value, whereas Opacity provides easier PSD compatibility.
While they can be used in combination, generally only one will be used, i.e. leave Opacity=1 and make use of transparency, or alternatively, leave Transparency=255 and make use of Opacity. For example, for 50% opacity: Transparency = 255 and Opacity = 0.5, or Transparency = 128 and Opacity = 1.0

procedure TForm1.DrawToCanvasWithAlpha1Click(Sender: TObject);
begin
  ImageEnView1.IEBitmap.DrawToCanvasWithAlpha(ImageEnView2.IEBitmap.Canvas, 10, 10, 255, 1);
  ImageEnView2.Update;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

HeartWare

Denmark
50 Posts

Posted - Feb 23 2018 :  05:12:09  Show Profile  Reply
Thank you. I had looked at that method, but thought that it would only use the transparency/opacity given in the call and ignore the one in the bitmap. Perhaps an additional text at the DrawToCanvas to the effect that it doesn't support transparency and to use DrawToCanvasWithAlpha for transparent drawing, and an elaboration in DrawToCanvasWithAlpha, that the specified transparency/opacity values are IN ADDITION to the alpha channel of the source bitmap, ie. an "overlay" on top of the already existing alpha channel.

Anyway - the function works as expected with 255,1 as transparency/opacity. Thank you for the assistance...
Go to Top of Page

xequte

39061 Posts

Posted - Feb 25 2018 :  17:20:46  Show Profile  Reply
Thanks, I have added a note to the documentation.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

HeartWare

Denmark
50 Posts

Posted - Feb 26 2018 :  00:42:29  Show Profile  Reply
The online help (https://www.imageen.com/help/TIEBitmap.DrawToCanvasWithAlpha.html and https://www.imageen.com/help/TIEBitmap.DrawToCanvas.html) hasn't been changed?
Go to Top of Page

xequte

39061 Posts

Posted - Feb 26 2018 :  14:37:32  Show Profile  Reply
No, the changes will push out to the web site with the next update.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: