I have come back to working on this collage project. It is working but there are some major problems. To recap, I am loading an image into layer 0 then placing 2 to 4 overlays on top. I am attempting to save the position including rotation of each overlay then the next time I am loading images with the previous settings. If there is no rotation this works well but when I rotate the numbers I save don't match.
This is a snippet of how I load up the images:
On form activate I set these values:
ImageEnView1.LayersRotationUseFilterOnPreview :=true; // make it fast preview
ImageEnView1.LayersRotationDelayFilterOnPreview := true;
ImageEnView1.SetLayersGripStyle(clBlack, clLime, bsSolid, 5, iegsCircle);
ImageEnView1.ForceALTkey := true; // aspect ratio
ImageEnView1.Blank;
ImageEnView1.LayersSync := false;
ImageEnView1.MouseInteract := [miMoveLayers, miResizeLayers {, miRotateLayers}];
This is my function to build the layout:
function TFRM_collage.BuildCollage(Sender: tObject;
layers: integer;
Image1, Image2, Image3, Image4: string;
shadow: boolean): integer;
var
localconfigName: string;
loop: integer;
ThisIni: TIniFile;
background: string;
top: integer;
left: integer;
maxsize: integer;
rotate: single;
shadowradius: integer;
shadowoffsetx: integer;
shadowoffsety: integer;
shadowintensity: integer;
Ratio: double;
schematic: string;
begin
SaveMove1 := 1; // set them all to their default values.
SaveMove2 := 2;
SaveMove3 := 3;
SaveMove4 := 4;
ImageEnView1.LayersRotationFilter := ierBicubic;
ImageEnView1.LayersRotationAntialias := true;
result := 0;
imageEnView1.Clear; // empty it all out
LocalConfigName := Form1.DataBasePath + '\layout' + inttostr(layers) + '.CLD';
if not fileexists(LocalConfigName) then
begin
result := loop;
MessageDlg('The Required Layout File Could Not Be Found:' + #13 + #10 + LocalConfigName, mtError, [mbOK], 0);
BTN_cancelClick(self);
exit;
end;
ThisIni := TIniFile.Create(LocalConfigName);
background := ThisIni.ReadString('fullpage', 'name', '');
if not fileexists(background) then
begin
result := -1;
MessageDlg('The Required Background File Could Not Be Found:' + #13 + #10 + background, mtError, [mbOK], 0);
BTN_cancelClick(self);
exit;
end;
// put the bckground image
imageEnView1.AutoShrink := true;
imageEnView1.IO.LoadFromFile(background);
imageEnView1.AutoShrink := true;
imageEnView1.layers[0].locked := true;
application.processmessages;
BackgroundHeight := imageEnView1.layers[0].height;
BackgroundWidth := imageEnView1.layers[0].width;
for loop := 1 to layers do
begin
application.processmessages;
top := ThisIni.ReadInteger('image' + inttostr(loop), 'top', 0);
left := ThisIni.ReadInteger('image' + inttostr(loop), 'left', 0);
maxsize := ThisIni.ReadInteger('image' + inttostr(loop), 'maxsize', 0);
rotate := ThisIni.Readfloat('image' + inttostr(loop), 'rotate', 0);
shadowradius := ThisIni.ReadInteger('image' + inttostr(loop), 'shadowradius', 0);
shadowoffsetx := ThisIni.ReadInteger('image' + inttostr(loop), 'shadowoffsetx', 0);
shadowoffsety := ThisIni.ReadInteger('image' + inttostr(loop), 'shadowoffsety', 0);
shadowintensity := ThisIni.ReadInteger('image' + inttostr(loop), 'shadowintensity', 0);
Layerrotateangle[loop] := rotate;
// Add the layer
ImageEnView1.LayersAdd;
// ImageEnView1.IO.Params.PSD_LoadLayers := true;
if loop = 1 then
imageEnView1.IO.LoadFromFile(Image1)
else if loop = 2 then
imageEnView1.IO.LoadFromFile(Image2)
else if loop = 3 then
imageEnView1.IO.LoadFromFile(Image3)
else if loop = 4 then
imageEnView1.IO.LoadFromFile(Image4);
// Rotate has to be dome before placing
if rotate <> 0 then
begin
imageEnView1.layers[loop].Rotate := rotate;
end;
if imageEnView1.layers[loop].Bitmap.Width > imageEnView1.layers[loop].Bitmap.height then // it is landscape
begin
Ratio := imageEnView1.layers[loop].Bitmap.height / imageEnView1.layers[loop].Bitmap.Width;
imageEnView1.layers[loop].width := MaxSize;
imageEnView1.layers[loop].height := round(Maxsize * Ratio);
end
else // no it is portrait
begin
Ratio := imageEnView1.layers[loop].Bitmap.Width / imageEnView1.layers[loop].Bitmap.height;
imageEnView1.layers[loop].height := MaxSize;
imageEnView1.layers[loop].width := round(Maxsize * Ratio);
end;
imageEnView1.Fit;
// imageEnView1.layers[loop].Rotate := rotate;
imageEnView1.layers[loop].PosX := left;
imageEnView1.layers[loop].PosY := top;
// imageEnView1.autoshrink := true;
if Shadow then
ImageEnView1.Proc.AddSoftShadow(shadowradius, shadowoffsetx, shadowoffsety, true, clblack, shadowintensity);
application.ProcessMessages;
end; //loop
ThisIni.free;
PNL_wait.Visible := false;
screen.Cursor := crdefault;
ImageEnView1.Update();
application.processmessages;
end;
Then once the images have been move and rotated I do this:
LocalConfigName := Form1.DataBasePath + '\layout' + inttostr(count) + '.CLD';
if not fileexists(LocalConfigName) then
begin
MessageDlg('The Required Layout File Could Not Be Found:' + #13 + #10 + LocalConfigName, mtError, [mbOK], 0);
BTN_cancelClick(self);
exit;
end;
ImageEnView1.LayersRotationAntialias := true;
ImageEnView1.LayersRotationFilter := ierBilinear;
ImageenView1.LayersFixRotations();
ImageenView1.Update();
ThisIni := TIniFile.Create(LocalConfigName);
for loop := 1 to count do
begin
ThisIni.writeinteger('image' + inttostr(loop), 'top', imageEnView1.layers[loop].PosY);
ThisIni.writeinteger('image' + inttostr(loop), 'left', imageEnView1.layers[loop].PosX);
ThisIni.writeinteger('image' + inttostr(loop), 'maxsize', imageEnView1.layers[loop].width);
if Layerrotated[loop] then
begin
ThisIni.writefloat('image' + inttostr(loop), 'rotate', Layerrotateangle[loop]);
end; //Layerrotated[loop]
end; // loop
application.ProcessMessages;
ThisIni.free;
// 20140806 added to merge all layers before finishing
imageEnView1.layersmergeAll;
ImageEnview1.IO.SaveToFileJpeg('c:\instevnt\collage\Collage' + inttostr(count) + '.jpg');
.....
I am sure I am doing at least a dozen things wrong. I need it to load up with all of the settings from last time.
Also, has any progress been made on keeping the layers from extending beyond the edge of the background image?
Thanks a lot for looking
Gary Gonnella