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
 embedding bitmap into metafile with transparency

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
davenovo Posted - Aug 25 2011 : 16:40:54
Hello.

I have a TIEBitmap that has an alpha channel where some pixels are partially transparent. I need to render that bitmap to a metafile and preserve the transparency. How can I do this?

I tried RenderToCanvasWithAlpha but that does not work if I pass in a metafile canvas. It does not work because RenderToCanvasWithAlpha tries to get the image from the metafileCanvas, but you cannot retreive an image from a metafile canvas in that way.

Any ideas?
3   L A T E S T    R E P L I E S    (Newest First)
davenovo Posted - Aug 26 2011 : 09:39:32
Hi Fabrizio,

Thanks. We will have to find a better way. I did not realize that the standard Metafile did not really have a way of supporting transparent bitmaps.
fab Posted - Aug 25 2011 : 23:51:19
I know another way, that has following limitations:

1) works only with alpha=0 or alpha=255. No semi-transparent pixels allowed.
2) it is very slow (for each pixel draws a rectangle on the canvas)
3) of course, when the metafile is scaled produces "big pixels"

Here is an example:


var
  x, y:integer;
  MetaFile:TMetaFile;
  MetaCanvas:TCanvas;
  bmp:TIEBitmap;
begin
  // load image with alpha in ImageEnView1
  ImageEnView1.IO.LoadFromFile('myimage.xxx');

  bmp := ImageEnView1.IEBitmap;
  MetaFile := TMetaFile.Create();
  MetaFile.Enhanced := true;
  MetaFile.Width := bmp.Width;
  MetaFile.Height := bmp.Height;
  MetaCanvas := TMetaFileCanvas.Create(MetaFile, 0);
  for y:=0 to bmp.Height-1 do
  begin
    for x:=0 to bmp.Width-1 do
    begin
      if bmp.AlphaChannel.Pixels_ie8[x, y] > 0 then
      begin
        MetaCanvas.Brush.Color := TRGB2TColor(bmp.Pixels[x, y]);
        MetaCanvas.FillRect(Rect(x, y, x+1, y+1));
      end;
    end;
  end;
  MetaCanvas.Free();
  MetaFile.SaveToFile('testmeta.emf');
  MetaFile.Free();
end;


TRGB2TColor is defined in "imageenproc" unit, while TIEBitmap in "hyieutils".
fab Posted - Aug 25 2011 : 23:27:23
Hello,
RenderToCanvasWithAlpha merges (alpha blend) source pixels with destination pixels, using source alpha channel. For this reason it needs to read pixels from destination.
Anyway it doesn't preserve the original alpha channel.

Actually I don't know a way to produce a metafile with embedded a bitmap+alpha channel: maybe it could be possible embedding a PNG (with alpha) into the metafile using GDI+.