Recent

Author Topic: How crop image?  (Read 9623 times)

Fortuna1

  • Full Member
  • ***
  • Posts: 164
How crop image?
« on: July 07, 2011, 04:13:09 pm »
How crop image?
Thanks

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How crop image?
« Reply #1 on: July 07, 2011, 04:32:05 pm »
On a TImage component?

Mando

  • Full Member
  • ***
  • Posts: 181
Re: How crop image?
« Reply #2 on: July 07, 2011, 04:55:33 pm »
see the project.

Load a bitmap  into image1, run an press button.


regards.
« Last Edit: July 07, 2011, 06:43:50 pm by Mando »

Fortuna1

  • Full Member
  • ***
  • Posts: 164
Re: How crop image?
« Reply #3 on: July 07, 2011, 06:59:00 pm »
On a TImage component?
Yes, I need crop  on a TImage component.


When tray your included sample  I get  message

The project requires the package "LCLBase (>=1.0.1)".
But it was not found. See Project -> Project Inspector.


I try this your sample in
linux and windows lazarus 0.9.30.1

But I get error 
The project requires the package "LCLBase (>=1.0.1)".
But it was not found. See Project -> Project Inspector.

Mando

  • Full Member
  • ***
  • Posts: 181
Re: How crop image?
« Reply #4 on: July 07, 2011, 07:07:06 pm »
You must remove LCLBase from the project.
Project->Project inspector. 

Remove LCLBase.

Compile

(Spanish?)

Fortuna1

  • Full Member
  • ***
  • Posts: 164
Re: How crop image?
« Reply #5 on: July 07, 2011, 07:42:40 pm »
Thanks!
Wiith your help I finally managed to


procedure CropBitmap(aBitmap: TBitmap; aRect: TRect);
var bmp:TBitmap; r: TRect;
begin
  r:=aRect;// offsetRect(r,-r.left,-r.top);
  bmp:=Tbitmap.create;
  bmp.SetSize(r.right,r.bottom);

  bmp.Canvas.CopyRect(r,aBitmap.Canvas,aRect);
  aBitmap.Assign(bmp);
  bmp.free;
end;

{ TForm1 }

procedure TForm1.BitBtn1Click(Sender: TObject);
var r: Trect;
begin
  r:=rect(0,0,Image1.width div 2,Image1.height div 2);
 // offsetRect(r,Image1.width div 4,Image1.height div 4);
  CropBitmap(Image1.Picture.Bitmap,r);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     Image1.Picture.LoadFromFile('/home/usb/tiskaj_blag/image4.png');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   Image1.Picture.SaveToFile('/home/usb/tiskaj_blag/imag.png');
end;




offsetRect not working in linux.

 

TinyPortal © 2005-2018