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
 Load a PNG file and copy it to a Bitmap
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

DRIGUS

21 Posts

Posted - Mar 05 2019 :  04:38:20  Show Profile  Reply
Hi *.*.

I use ImageEn (8.3.0) and try to load a PNG file and copy it to a Graphics.TBitmap for further processing. The transparent parts of the PNG file should have a user defined color. I tried the following:


  Buffer := Graphics.TBitmap.Create;
  ImageIO := TImageEnIO.Create(nil);
  ImageIO.AttachedBitmap := Buffer;
  ImageIO.Background := aBackgroundColor; // f.e. clWhite
  ImageIO.LoadFromFile(FileName);


But the transparent parts are always black. How can I define the color for the transparent parts of the PNG?


Greetrings

xequte

38198 Posts

Posted - Mar 05 2019 :  16:57:37  Show Profile  Reply
Hi

Rather than use a TBitmap to handle the alpha, which can be problematic, use a TIEBitmap.

// Load a transparent PNG, remove the alpha channel (merging with a white background). Then assign it to a TBitmap
aBmp := TIEBitmap.Create;
aBmp.Read('D:\TransparentImage.png');
aBmp.RemoveAlphaChannel( True, clWhite );
aBmp.CopyToTBitmap( MyTBitmap );
aBmp.free;


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

DRIGUS

21 Posts

Posted - Mar 06 2019 :  04:21:28  Show Profile  Reply
This works, thanks. I only query HasAlphaChannel before removing the alpha channel because I have to load a wide range of image files and still use TImageEnIO in order to receive the OnProgress event.


Greetings
Go to Top of Page

xequte

38198 Posts

Posted - Mar 06 2019 :  22:48:20  Show Profile  Reply
Hi

In the next version TIEBitmap will have a progress event, but you can use:


// Load a transparent PNG, remove the alpha channel (merging with a white background). Then assign it to a TBitmap
aBmp := TIEBitmap.Create;
ImageIO := TImageEnIO.Create(nil);
ImageIO.AttachedBitmap := aBmp;
ImageIO.LoadFromFile(FileName);
aBmp.RemoveAlphaChannel( True, clWhite );
aBmp.CopyToTBitmap( MyTBitmap );
ImageIO.Free;
aBmp.free;


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

DRIGUS

21 Posts

Posted - Mar 07 2019 :  03:07:40  Show Profile  Reply
This is what I already do. But I do it without creating a TIEBitmap:


  ImageIO := tImageEnIO.Create(nil);
  ImageIO.OnProgress := SetProgress;
  ImageIO.LoadFromFile(FileName);
  Buffer := Graphics.tBitmap.Create;
  if ImageIO.IEBitmap.HasAlphaChannel then
    ImageIO.IEBitmap.RemoveAlphaChannel(True, clWhite);
  ImageIO.IEBitmap.CopyToTBitmap(FPrnBuffer);
  ImageIO.Free;


I saw that there is a


  fIEBitmap := TIEBitmap.Create;


in TImageEnIO.Create. Is this O.K. or should I always attach a TIEBitmap by myself?


Greetings
Go to Top of Page

xequte

38198 Posts

Posted - Mar 07 2019 :  15:08:10  Show Profile  Reply
Hi

That is fine too.



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

DRIGUS

21 Posts

Posted - Mar 08 2019 :  02:41:48  Show Profile  Reply
Thanks for the fast and excellent support.


Greetings
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: