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
 how to crop image and save
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

aftereffectniko

Ethiopia
23 Posts

Posted - Jun 26 2013 :  09:40:20  Show Profile  Reply
i'm trying to make photo frame software , there is 2 layer , the first layer is user photo the second layer is frame png.. when i try to merje and save the picture , the first layer get big like in the attached picture, i want to cut..

w2m

USA
1990 Posts

Posted - Jun 26 2013 :  10:03:12  Show Profile  Reply
Show the code you are using.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

Prg

7 Posts

Posted - Jun 26 2013 :  12:20:40  Show Profile  Reply
So, you can do it without any "manual" calculating and cropping:

ImageEnView1.LayersInsert(0);
ImageEnView1.Layers[0].Width := ImageEnView1.Layers[2].Width;
ImageEnView1.Layers[0].Height := ImageEnView1.Layers[2].Height;
ImageEnView1.Layers[0].Visible := False;
ImageEnView1.Layers[1].Cropped := True;
ImageEnView1.LayersMergeAll;
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jun 26 2013 :  13:20:24  Show Profile  Reply
Can you upload the original image you want to frame?
Can you upload the frame image?
Finally can you upload an image of what you want the framed image to look like?

William Miller
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jun 27 2013 :  06:56:49  Show Profile  Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: