Recent

Author Topic: manipulate images - help  (Read 21238 times)

fachamix

  • New member
  • *
  • Posts: 6
manipulate images - help
« on: December 30, 2009, 03:43:37 pm »
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

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: manipulate images - help
« Reply #1 on: December 30, 2009, 04:45:33 pm »
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...  :o
Lazarus 1.7 (SVN) FPC 3.0.0

krsears

  • New Member
  • *
  • Posts: 19
Re: manipulate images - help
« Reply #2 on: December 30, 2009, 06:34:58 pm »
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

  • Sr. Member
  • ****
  • Posts: 275
Re: manipulate images - help
« Reply #3 on: December 30, 2009, 07:18:23 pm »
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

  • Jr. Member
  • **
  • Posts: 54
  • Computer Programmer/www.NewsRx.com
    • ᏣᎳᎩ ᎦᏬᏂᎯᏍᏗ ᏗᏕᎶᏆᏍᏗ (Cherokee Language Lessons)
This WIKI link may help: Re: manipulate images - help
« Reply #4 on: December 30, 2009, 09:24:31 pm »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: This WIKI link may help: Re: manipulate images - help
« Reply #5 on: December 30, 2009, 10:15:57 pm »
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.Canvas,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.Bitmap.Width,Image2.Picture.Bitmap.Height),Bmp);
  Bmp.free;
end;
« Last Edit: December 30, 2009, 10:20:43 pm by theo »

fachamix

  • New member
  • *
  • Posts: 6
Re: manipulate images - help
« Reply #6 on: December 30, 2009, 11:58:31 pm »
incredible... thanks a lot!

VTwin

  • Hero Member
  • *****
  • Posts: 927
  • Former Turbo Pascal 3 user
Re: This WIKI link may help: Re: manipulate images - help
« Reply #7 on: March 28, 2011, 10:19:34 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
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.8 (64 bit Cocoa, also fixes and trunk)
Ubuntu 18.04.3: Lazarus 2.0.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.8 (64 bit on VBox)

gyts

  • Jr. Member
  • **
  • Posts: 96
Re: manipulate images - help
« Reply #8 on: March 29, 2011, 04:14:45 pm »
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

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: manipulate images - help
« Reply #9 on: July 11, 2013, 09:16:55 am »
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.
« Last Edit: July 11, 2013, 09:20:18 am by User137 »

circular

  • Hero Member
  • *****
  • Posts: 3440
    • Personal webpage
Re: manipulate images - help
« Reply #10 on: July 18, 2013, 02:37:34 pm »
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;
Conscience is the debugger of the mind

bonmario

  • Sr. Member
  • ****
  • Posts: 309
Re: This WIKI link may help: Re: manipulate images - help
« Reply #11 on: March 27, 2014, 08:26:02 pm »
Zoom 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.Canvas,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.Bitmap.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

 

TinyPortal © 2005-2018