Solved

Zooming TImage

Posted on 2006-06-24
10
562 Views
Last Modified: 2010-04-05
Hello Again,

 Can anybody show me how to create a Zoom for TImage? Drag the cursor and form a dotted box on the area where i want to zoom, when i release the left button, the TImage will zoom.

Can any body show me a source code for this?

Thanks in advance.
0
Comment
Question by:ryan_sabarre
  • 7
  • 3
10 Comments
 

Author Comment

by:ryan_sabarre
ID: 16977733
Hi everybody,

 First things first, Does mySQL accept jpg files?

I used this to save image in my Media (blob fieldtype)
   ms := TMemoryStream.Create;
   Image1.Picture.Graphic.SaveToStream(ms);
   ms.Position := 0;
   TBlobField(oTable.FieldByName('MEDIA')).LoadFromStream(ms);
-------------------------------------------------------
And used this to load my image in the TIMAGE

Procedure TfDigitalMed.InitializeForm;
var
  ms : TStream;
  gr : TBitmap;
begin
  ms := oTable.CreateBlobStream(oTable.FieldByName('MEDIA'), bmRead);
  gr := TBitmap.Create;
  gr.LoadFromStream(ms);
  Image1.Picture.Bitmap.Assign(gr);
  gr.Free;
  ms.Free;
end;
---------------------------------------------------------------
When any file(.jpg,etc..) except for ".bmp" is loaded using my (InitializeForm;) it will return a "Bitmap image is not valid".

0
 

Author Comment

by:ryan_sabarre
ID: 16977749
correction field "Media" is type LONGBLOB
0
 

Author Comment

by:ryan_sabarre
ID: 16979137
anybody?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 16980392
Place an image with bitmap on a form.
And below is code.

> gr := TBitmap.Create;
> gr.LoadFromStream(ms);
If You ceate bitmap You can only load bitmap.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, math;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    x0,y0: integer;
    xp,yp: integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if ssLeft in Shift then
    begin
    Image1.Canvas.Pen.Mode := pmNot;
    Image1.Canvas.Brush.Style := bsClear;
    Image1.Canvas.Rectangle(Rect(x0,y0,xp,yp));
    Image1.Canvas.Rectangle(Rect(x0,y0,X,Y));
    xp := X;
    yp := Y;
    end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  x0 := X;
  y0:= Y;
  xp := x0;
  yp := y0;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  StretchBlt(Image1.Canvas.Handle,0,0,Image1.Width,Image1.Height,Image1.Canvas.Handle,
  min(x0,xp)+1,min(y0,yp)+1,abs(xp-x0)-2,abs(yp-y0)-2,SRCCOPY);
  Image1.Invalidate;
end;

end.
0
 
LVL 17

Expert Comment

by:mokule
ID: 16980409
To load jpg image create TJPegImage
0
 

Author Comment

by:ryan_sabarre
ID: 16981334
Mokule,
  by the way how can i unzoom it?

thanks.


procedure TForm1.Button1Click(Sender: TObject);
begin
 IF OpenPictureDialog1.EXECUTE THEN
  BEGIN
   IMAGE1.Picture.LoadFromFile(OpenPictureDialog1.FILENAME);
  END;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
function min(x1,x2:Integer):Integer;
 Begin
  if not (x1 < x2) then
  Begin
   result := x2;
  end
  else
  begin
    result :=  x1;
  end;
 End;
begin

StretchBlt(Image1.Canvas.Handle,0,0,Image1.Width,Image1.Height,Image1.Canvas.Handle,
  min(x0,xp)+1,min(y0,yp)+1,abs(xp-x0)-2,abs(yp-y0)-2,SRCCOPY);
  Image1.Invalidate;
 
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 x0 := X;
  y0:= Y;
  xp := x0;
  yp := y0;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 if ssLeft in Shift then
    begin
    Image1.Canvas.Pen.Mode := pmNot;
    Image1.Canvas.Brush.Style := bsClear;
    Image1.Canvas.Rectangle (x0,y0,xp,yp);
    Image1.Canvas.Rectangle(x0,y0,X,Y);
    xp := X;
    yp := Y;
    end;
end;
0
 

Author Comment

by:ryan_sabarre
ID: 16981345
By the way, this does not work when JPG is used as image.
0
 

Author Comment

by:ryan_sabarre
ID: 16998831
hello anybody?
0
 
LVL 17

Expert Comment

by:mokule
ID: 17000680
You should always use bitmap.
first load to jpegimage and then assign it to bitmap.
To zoom out you must have original bitmap stored somewhere or load it again.
0
 

Author Comment

by:ryan_sabarre
ID: 17107944
Mokule, Thanks a lot.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question