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
 Retain Alpha Transparency on 32bit RGB Export
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PaulAtMass

United Kingdom
19 Posts

Posted - Apr 08 2020 :  09:45:55  Show Profile  Reply
Hi, I'm having trouble retaining the background and fill transparency when writing/saving a TIELayer to a 32bit bitmap file or VCL Bitmap. See code below:
I really need to convert a TIELayer to a 32bit RBGA bitmap to create a video overlay frame. See attached PowerPoint for different image files.


  { Create transparent 200x200 yellow circle layer. }
  LLyrRect := Rect( 0, 0, 200, 200);
  IEView.LayersAdd( iesEllipse, LLyrRect, clYellow, 1, clYellow );
  LLyr         := IEView.CurrentLayer;
  LLyr.Opacity := 0.5;  { Doesn't work on PNG file }
//  LLyr.FillOpacity := 0.5;   { Does work on PNG file but pen solid }
  LLyr.ConvertToImageLayer(1, False);
  IEView.Update();
  LLyr.Bitmap.Write( 'IELayer PNG.png');   //Background Transparent but fill not.
  LLyr.Bitmap.Write( 'IELayer BMP.bmp');   //Neither background or fill transparent.
  Image2.Picture.Assign(LLyr.Bitmap.VclBitmap);

  //Try setting pixel format and using SynchronizeRGBA.
  IEBmpOvr := TIEBitmap.Create(LLyr.Bitmap);
  IEBmpOvr.PixelFormat := ie32RGB;
  IEBmpOvr.Write( 'IEBitmap BMP.bmp');
  IEBmpOvr.Free();
  IEBmpOvr := TIEBitmap.Create(LLyr.Bitmap);
  IEBmpOvr.SynchronizeRGBA( False, True);  //Convert 24bit image + alpha channel to 32bit RGBA.
  IEBmpOvr.Write( 'IEBitmap Sync BMP.bmp');

  { Create video overlay frame using Bitmap Handle (assumes 32RGBA format). }
  if m_pFrameFactory = nil then
    m_pFrameFactory := CreateComObject(CLASS_MFFactory) as IMFFactory;
   m_pFrameFactory.MFFrameCreateFromHBITMAP( IEBmpOvr.VclBitmap.Handle, CursorData.MFCsrOverlay, '');
//  m_pFrameFactory.MFFrameCreateFromFile('IILayer PNG.png', CursorData.MFCsrOverlay, '');



xequte

38207 Posts

Posted - Apr 09 2020 :  22:54:44  Show Profile  Reply
Hi Paul

It is not intended that layers be a way of outputting content. Layers are just part of a greater image, which is output. So, for instance Opacity is only a display property that does not affect the image itself until you flatten the image (i.e. merge it to the background).

  // Create a PNG with a 50% transparent ellipse
  ImageEnView1.Blank;
  aRect := Rect( 0, 0, 200, 200);
  ImageEnView1.LayersAdd( iesEllipse, aRect, clNone, 0, clRed );
  ImageEnView1.CurrentLayer.Opacity := 0.5;

  // Merge with Alpha Compositing
  ImageEnView1.LayersMergeAll( True );

  ImageEnView1.IO.SaveToFile( 'D:\out.png');



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