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
 Making the whole image transparent
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

933 Posts

Posted - Dec 05 2021 :  06:22:12  Show Profile  Reply
I use this code to make the whole image transparent (which does work):

ImageEnView1.Layers[0].Transparency := 128;


However, afterwards, HasAlphaChannel(True) still reports the image as not having transparent areas:

ImageEnView1.Layers[0].Transparency := 128;
CodeSite.Send('ImageEnView1.IEBitmap.HasAlphaChannel(True)', ImageEnView1.IEBitmap.HasAlphaChannel(True)); // False!


Is the first or the second procedure wrong?

xequte

38611 Posts

Posted - Dec 07 2021 :  02:38:39  Show Profile  Reply
Hi Peter

> ImageEnView1.Layers[0].Transparency := 128;

This only makes the layer *display* as half transparent (the tranparency will become fixed if convert to image layer/flatten).


> ImageEnView1.IEBitmap.HasAlphaChannel(True)); // False!

This checks whether the image itself has any alpha (e.g. an image loaded from a PNG file).



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

PeterPanino

933 Posts

Posted - Dec 07 2021 :  08:49:00  Show Profile  Reply
Hi Nigel

But how do I flatten the Background Layer? I get an AV when I do this:

ImageEnView1.LayersMerge([0, 0]);


And when I do:

ImageEnView1.LayersMerge([]);


...then any other existing layers are merged too which I do not want.
Go to Top of Page

xequte

38611 Posts

Posted - Dec 07 2021 :  13:29:41  Show Profile  Reply
You can use Layer[0].ConvertToImageLayer();

// Convert an image layer with 50% opacity to an image with 50% alpha
ImageEnView1.LayersAdd( ielkImage );
TIEImageLayer( ImageEnView1.CurrentLayer ).Bitmap.Read( 'D:\MyImage.jpeg' );
ImageEnView1.CurrentLayer.Opacity := 0.50;
ImageEnView1.CurrentLayer.ConvertToImageLayer();

https://www.imageen.com/help/TIELayer.ConvertToImageLayer.html


But using layer functionality is overkill if all you want to do is make an image transparent. You can just work with the alpha channel instead:

ImageEnView1.IEBitmap.AlphaFill( 128 );
ImageEnView1.Update();

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

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

PeterPanino

933 Posts

Posted - Dec 09 2021 :  10:57:23  Show Profile  Reply
Hi Nigel,

Thanks!

IEBitmap.AlphaFill is a perfect solution, as it optionally supports even gradient transparency!
Go to Top of Page

PeterPanino

933 Posts

Posted - Dec 09 2021 :  11:14:48  Show Profile  Reply
Hi,

how do I apply gradient transparency explicitly to a SELECTION?

ImageEnView1.SetSelectedAreaAlpha does not allow gradient transparency.

It would be useful if ImageEnView1.IEBitmap.AlphaFill (even with gradient transparency) would be automatically applied to the selected area IF a selection exists (otherwise to the whole image)!

A workaround would be:
1. Copy the selection area to a temporary IEBitmap
2. Apply the gradient transparency to that temporary IEBitmap
3. Then copy the temporary IEBitmap back to the selection area

Isn't there already a built-in method to do this?
Go to Top of Page

xequte

38611 Posts

Posted - Dec 09 2021 :  14:01:53  Show Profile  Reply
Hi Peter

You can use:

ImageEnView1.IEBitmap.AlphaChannel.GradientFillRect();

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

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