manipulate images - help lazarus / 39-Graphics ---------------------------------------------------------------------- fachamix · 2009-12-30 14:43 how can i show an image in a form , and maniplate it , for example, to  ZOOM IT , rotate it , etc ... specially to ZOOM IT ---------------------------------------------------------------------- Ocye · 2009-12-30 15:45 There is no function like Canvas.Zoom() or Rotate(), you have to calculate it yourself. Rotate is done by sin/cos of each pixel (or scanline), Zoom would be possible with Canvas.StretchDraw(). Of course, you could use your preferred internet search machine too and look for "image processing" and pascal. Maybe you will find OpBitmap by Theo... ---------------------------------------------------------------------- krsears · 2009-12-30 17:34 you can do a rudimentary zoom thus:   put a TImage in a TPanel   set the TImage size larger/smaller than the size of the enclosing TPanel by the zoom ratio desired   set the TImage to stretch the contents to pan around a "zoomed in" image change the left/top coordinates on the TImage appropriately. Kendall ---------------------------------------------------------------------- clauslack · 2009-12-30 18:18 I have a workarround download the image from database (tiff, jpg, gif) and open this with an external image viewer(with TProcess), that support all this stuff (rotate, zoom, print) like ACDSee.exe Regards ---------------------------------------------------------------------- Mike J · 2009-12-30 20:24 http://wiki.lazarus.freepascal.org/PascalMagick About ImageMagick ImageMagick is a free software suite developed to create, edit, and compose bitmap images. It supports a huge variety of formats (over 90) including formats like GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. Images can be cropped, colors can be changed, various effects can be applied, images can be rotated and combined, and text, lines, polygons, ellipses and Bézier curves can be added to images and stretched and rotated. The suite runs on all major operating systems and it can also be used from the command line and it´s command line tools package is one of Linux standard packages, being distributed with many distribution ---------------------------------------------------------------------- theo · 2009-12-30 21:15 There is no need for external tools for this job. Zoom can be done with Canvas.CopyRect, Canvas.StretchDraw. See Below. An example for Rotate90 is here: http://www.lazarusforum.de/viewtopic.php?p=33489#p33489 Just remove the two lines which set "PixelFormat". Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var Bmp:TBitmap; aWidth,aHeight,aLeft,aTop:integer; begin   aWidth:=80;   aHeight:=80;   aTop:=20;   aLeft:=30;   Bmp:=TBitmap.Create;   Bmp.Width:=aHeight;   Bmp.Height:=aWidth;   Bmp.Canvas.CopyRect(Rect(0,0,aWidth,aHeight),Image1.Picture.Bitmap.C anvas,Rect(aLeft,aTop,aLeft+aWidth, aTop+aHeight));   Image2.Picture.Bitmap.SetSize(Image2.Width,Image2.Height);   Image2.Picture.Bitmap.Canvas.StretchDraw(Rect(0,0,Image2.Picture.Bit map.Width,Image2.Picture.Bitmap.Height),Bmp);   Bmp.free; end; ---------------------------------------------------------------------- fachamix · 2009-12-30 22:58 incredible... thanks a lot! ---------------------------------------------------------------------- VTwin · 2011-03-28 20:19 Quote from: theo on December 30, 2009, 10:15:57 pm An example for Rotate90 is here: http://www.lazarusforum.de/viewtopic.php?p=33489#p33489 Just remove the two lines which set "PixelFormat". I know this is an old thread, but the example flips the image as well as rotates it. So maybe the following is useful to someone: Code: [Select]procedure RotateBitmap90(const bitmap: TBitmap); var   tmp: TBitmap;   src, dst: TLazIntfImage;   ImgHandle, ImgMaskHandle: HBitmap;   i, j, t, u, v: integer; begin   tmp := TBitmap.create;   tmp.Width := Bitmap.Height;   tmp.Height := Bitmap.Width;   dst := TLazIntfImage.Create(0, 0);   dst.LoadFromBitmap(tmp.Handle, tmp.MaskHandle);   src := TLazIntfImage.Create(0, 0);   src.LoadFromBitmap(bitmap.Handle, bitmap.MaskHandle);   u := bitmap.width - 1;   v := bitmap.height - 1;   for i := 0 to u do begin     t := u - i;     for j := 0 to v do       dst.Colors[j, t] := src.Colors[i, j];   end;   dst.CreateBitmaps(ImgHandle, ImgMaskHandle, false);   tmp.Handle := ImgHandle;   tmp.MaskHandle := ImgMaskHandle;   dst.Free;   bitmap.Assign(tmp);   tmp.Free;   src.Free; end;  Easy to modify for 180 and 270 rotations, and mirroring. Cheers, Frederick ---------------------------------------------------------------------- gyts · 2011-03-29 14:14 This is my resize program. Maybe it will be usefull to someone. Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   ExtCtrls, ComCtrls; type   { TForm1 }   TForm1 = class(TForm)     Image: TImage;     Bckg: TPaintBox;     TB: TTrackBar;     procedure FormCreate(Sender: TObject);     procedure TBChange(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   i, r: TRect;   x, y, xx, yy: integer; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin   Image.Picture.LoadFromFile ('02.jpg');   y := 0;   x := 0;   xx := Bckg.Width;   yy := Bckg.Height;   r.Top := y; r.Left := x; r.Right := xx; r.Bottom := yy;   i.Top := 0;   i.Left := 0;   i.Right := Image.Width;   i.Bottom := Image.Height;   Bckg.Canvas.CopyRect(r, Image.Picture.Bitmap.Canvas, i); end; procedure TForm1.TBChange(Sender: TObject); begin   r.Top := trunc(y * TB.Position / 100);   r.Left := trunc(x * TB.Position / 100);   r.Right := trunc(xx * TB.Position / 100);   r.Bottom := trunc(yy * TB.Position / 100);   Bckg.Canvas.CopyRect(r, Image.Picture.Bitmap.Canvas, i); end; initialization   {$I unit1.lrs} end. LFM: Code: [Select]object Form1: TForm1   Left = 237   Height = 768   Top = 110   Width = 1024   Caption = 'Form1'   ClientHeight = 768   ClientWidth = 1024   OnCreate = FormCreate   LCLVersion = '0.9.28.2'   object Bckg: TPaintBox     Left = 0     Height = 768     Top = 0     Width = 1024   end   object Image: TImage     Left = 1040     Height = 768     Top = 102     Width = 1024   end   object TB: TTrackBar     Left = 320     Height = 25     Top = 743     Width = 384     Max = 100     OnChange = TBChange     Position = 100     TabOrder = 0   end end ---------------------------------------------------------------------- User137 · 2013-07-11 07:16 On present day it seems BGRABitmap is the most used graphics library for Lazarus. There is even a forum section dedicated to it: http://forum.lazarus.freepascal.org/index.php/board,46.0.html But notice that image manipulation is CPU consuming "trickery"    If you want real performance to it, you need to learn using OpenGL. Then you'll get the power of GPU to help you. ---------------------------------------------------------------------- circular · 2013-07-18 12:37 Yes, in BGRABitmap you have functions to do rotation of any angle: Code: [Select]    procedure PutImage(x, y: integer; Source: TBGRACustomBitmap; mode: TDrawMode; AOpacity: byte = 255); override;     procedure PutImageAngle(x,y: single; Source: TBGRACustomBitmap; angle: single; imageCenterX: single = 0; imageCenterY: single = 0; AOpacity: Byte=255; ARestoreOffsetAfterRotation: boolean = false); override;     procedure PutImageAffine(Origin,HAxis,VAxis: TPointF; Source: TBGRACustomBitmap; AOpacity: Byte=255); override; There is an existing thread about it: http://forum.lazarus.freepascal.org/index.php/topic,17896.0.html There also simple rotation functions: Code: [Select]    procedure VerticalFlip; override;     procedure HorizontalFlip; override;     function RotateCW: TBGRACustomBitmap; override;     function RotateCCW: TBGRACustomBitmap; override; ---------------------------------------------------------------------- bonmario · 2014-03-27 19:26 Quote from: theo on December 30, 2009, 10:15:57 pmZoom can be done with Canvas.CopyRect, Canvas.StretchDraw. See Below. Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var Bmp:TBitmap; aWidth,aHeight,aLeft,aTop:integer; begin   aWidth:=80;   aHeight:=80;   aTop:=20;   aLeft:=30;   Bmp:=TBitmap.Create;   Bmp.Width:=aHeight;   Bmp.Height:=aWidth;   Bmp.Canvas.CopyRect(Rect(0,0,aWidth,aHeight),Image1.Picture.Bitmap.C anvas,Rect(aLeft,aTop,aLeft+aWidth, aTop+aHeight));   Image2.Picture.Bitmap.SetSize(Image2.Width,Image2.Height);   Image2.Picture.Bitmap.Canvas.StretchDraw(Rect(0,0,Image2.Picture.Bit map.Width,Image2.Picture.Bitmap.Height),Bmp);   Bmp.free; end; Excuse me if i resume this old post. The code that i have quoted resize Image1 in Image2 and Image2 is an image with width and height = 80 pixel? Thanks in advance, Mario