Solved

Zooming TImage

Posted on 2006-06-24
10
559 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 89
Delphi TcxGrid group footer summary 3 210
creating threads in delphi 1 82
Adoquery sql  left join does not work 25 80
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now