Solved

Zooming TImage

Posted on 2006-06-24
10
577 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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