Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
T O P I C R E V I E W
tvdien
Posted - Jan 13 2012 : 06:46:38 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?
4 L A T E S T R E P L I E S (Newest First)
tvdien
Posted - Jan 13 2012 : 10:27:57 Great. :)
fab
Posted - Jan 13 2012 : 09:33:08 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;
tvdien
Posted - Jan 13 2012 : 07:36:00 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?
fab
Posted - Jan 13 2012 : 07:19:16 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.