Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Zooming TImage

Posted on 2006-06-24
10
Medium Priority
?
598 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Accepted Solution

by:
mokule earned 500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 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