Recent

Author Topic: Simple editing image  (Read 3300 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Simple editing image
« on: July 20, 2012, 03:16:50 pm »
Hello guys, how can I extract a portion of the image contained within a TPicture? In order to save it then as I want it cut?!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Simple editing image
« Reply #1 on: July 20, 2012, 04:02:39 pm »
Something like this should do. 

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  b:TBitmap;
begin
  //lets copy a 100 by 100 pixels, at offset 100,100 from a TImage
  b := TBitmap.Create;
  try
    b.Width := 100;
    b.height := 100;
    b.canvas.draw(-100,-100,image1.Picture.Graphic);
    b.SaveToFile('d:\temp.bmp');
  finally
    b.free;
  end;
end; 

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Simple editing image
« Reply #2 on: July 21, 2012, 06:00:51 pm »
Thanks, it works. But now I need to know one more thing. I imported the image I have set the TImage object with Proportional:=TRUE and I centered the image. How do I know the proportions of the image you just loaded (which is smaller than the image file). thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Simple editing image
« Reply #3 on: July 23, 2012, 11:46:02 am »
Quote
How do I know the proportions of the image

Well the proportions of the image are always the same whatever the size, if Proportional is set.

I assume you mean what are the dimensions on the image on screen?
If so there is a protected method called DestRect, to get at the protected method we can use a Cracker Class.  Here is an example ->

Code: [Select]
type
  TCustomImageCrack = class(TCustomImage)
  end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  dr:TRect;
begin
  dr := TCustomImageCrack(image1).destrect;
  showmessage(format('Width=%d, Height=%d',[dr.Right-dr.left,dr.Bottom-dr.top]));
end;     
« Last Edit: July 23, 2012, 11:47:53 am by KpjComp »

 

TinyPortal © 2005-2018