Solved

Zooming TImage

Posted on 2006-06-24
10
556 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
Comment Utility
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
Comment Utility
correction field "Media" is type LONGBLOB
0
 

Author Comment

by:ryan_sabarre
Comment Utility
anybody?
0
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
Comment Utility
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
Comment Utility
To load jpg image create TJPegImage
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:ryan_sabarre
Comment Utility
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
Comment Utility
By the way, this does not work when JPG is used as image.
0
 

Author Comment

by:ryan_sabarre
Comment Utility
hello anybody?
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
Comment Utility
Mokule, Thanks a lot.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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