You can try this, but I can not guarantee that it will work correctly with your pictures and frames. That said here is some code to merge two layers into a framed picture:
procedure TForm1.Frame1Click(Sender: TObject);
{ Combine two layers into one. layer 0 contains the picture, layer 1 contains the frame. The area
inside the frame image must be transparent or have an alpha of 0. The frameheight is estimated
from on the the location of the first pixel in layer 1 that has an alpha value of 0. The layers
are repositioned (PosX and PosY) to fit the frame in layer 1 to the picture in layer 0. This may
not perform correctly with some frame bitmaps because the estimate of the frame height is just
that... an estimate, however my testing with a number of picture sizes and frames produces good
results. }
var
i: integer;
iAlpha: integer;
iFrameHeight: integer;
begin
{ Get the first pixel with alpha = 0, then estimate the iFrameHeight }
for i := 0 to ImageEnView1.Layers[1].Bitmap.Height - 1 do
begin
iAlpha := ImageEnView1.Layers[1].Bitmap.Alpha[ImageEnView1.Layers[1].Bitmap.Width div 2, i];
if iAlpha = 0 then
begin
iFrameHeight := i*10;
break;
end
else
iFrameHeight := 100;
end;
{ Photo is in layer 0, so resize layer 0 to provide room for the frame in layer 1 }
ImageEnView1.Layers[0].PosX := -iFrameHeight;
ImageEnView1.Layers[0].PosY := -iFrameHeight;
ImageEnView1.Layers[0].Width := ImageEnView1.Layers[0].Bitmap.Width;
ImageEnView1.Layers[0].Height := ImageEnView1.Layers[0].Bitmap.Height;
{ Frame is in Layer 1 so stretch the layer to fit the photo in layer 0 }
ImageEnView1.Layers[1].PosX := -iFrameHeight * 2;
ImageEnView1.Layers[1].PosY := -iFrameHeight * 2;
ImageEnView1.Layers[1].Width := ImageEnView1.Layers[0].Bitmap.Width + iFrameHeight * 2;
ImageEnView1.Layers[1].Height := ImageEnView1.Layers[0].Bitmap.Height + iFrameHeight * 2;
{ Combine the layers }
ImageEnView1.LayersMergeAll;
ImageEnView1.Fit;
end;

35.07 KB

1.2 KB

39.72 KB
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html