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
 Cropping to background
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

tvdien

11 Posts

Posted - Jan 13 2012 :  06:46:38  Show Profile  Reply
With the following code I expected to have a result that's 640x640, but that's not the case.

  with ImageEnView1 do
  begin
    IO.LoadFromFile('C:\pic\bg.png'); //640x640
    LayersAdd;
    IO.LoadFromFile('C:\pic\prod.jpg'); //1600x1200
    CurrentLayer.Cropped := True;
    IO.SaveToFileJpeg('C:\test.jpg'); //1600x1200
  end;

What did I forget about?

fab

1310 Posts

Posted - Jan 13 2012 :  07:19:16  Show Profile  Reply
SaveToFileJpeg saves the current layer, that is the last added (1600x1200).
If you want to put prod.jpg over bg.png, cutting to the background (640x640), you have to merge them before save (jpeg doesn't support multiple layers). For example:
with ImageEnView1 do
begin
    IO.LoadFromFile('C:\pic\bg.png');
    LayersAdd;
    IO.LoadFromFile('C:\pic\prod.jpg');
    CurrentLayer.Cropped := True;
    LayersMergeAll();   // <<<<<<
    IO.SaveToFileJpeg('C:\test.jpg'); 
end;

LayersMergeAll() merges layer 0 and 1 and removes layer 1.
Of course the content of "bg.png" will be never visible.
Go to Top of Page

tvdien

11 Posts

Posted - Jan 13 2012 :  07:36:00  Show Profile  Reply
Of course in my saved file, the layers will be merged, but I don't want the layers to merge in the ImageEnView that the user is presented with. Does this leave me with no option but to create a second ImageEnView, copy all the layers, merge them and then save the result of that? Can I use a smaller object for this purpose?
Go to Top of Page

fab

1310 Posts

Posted - Jan 13 2012 :  09:33:08  Show Profile  Reply
No need to have another TImageEnView. Use a temporary TIEBitmap and LayersDrawTo, for example:

  with ImageEnView1 do
  begin
    IO.LoadFromFile('C:\pic\bg.png'); //640x640
    LayersAdd;
    IO.LoadFromFile('C:\pic\prod.jpg'); //1600x1200
    CurrentLayer.Cropped := True;
  end;

  // of course you need also "var bmp:TIEBitmap"
  bmp := TIEBitmap.Create(ImageEnView1.Layers[0].Width, ImageEnView1.Layers[0].Height);
  try
    ImageEnView1.LayersDrawTo(bmp);
    bmp.Write('C:\test.jpg');
  finally
    bmp.Free();
  end;

Go to Top of Page

tvdien

11 Posts

Posted - Jan 13 2012 :  10:27:57  Show Profile  Reply
Great. :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: