dia21
asked on
Zoom in and zom out an image
I have a form,a coolbar and a Timage with alclient. When i load a image i want that the form resize it after the size of a image and if the image is higher than the screen then to shrink it to fit in the maximized form and write the procent of the shrinked image.
Also i want to zoom in and zoom out the image on the form by typing the the procent(ex when i type 200% to zoom with 200%).
Also i want to zoom in and zoom out the image on the form by typing the the procent(ex when i type 200% to zoom with 200%).
ASKER
hi esoftbg, thank you
1. I want that the zoomed image to be shown in the center of the screen if it's smaller then the form
2. How can i set it back to original view because if i put 100 is not working
3. what about the first part of the question. if the image is smaller than the form i want that the form "surrounds" the image(the form to be resize based on the image)
Regards
1. I want that the zoomed image to be shown in the center of the screen if it's smaller then the form
2. How can i set it back to original view because if i put 100 is not working
3. what about the first part of the question. if the image is smaller than the form i want that the form "surrounds" the image(the form to be resize based on the image)
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I used this:
form borderstyle:=bsSingle
Window State:= wsMaximized
autoscroll:=true
I've chanced my mind and i want to stay the form all the time maximized, but i have 3 pb:
1. when i double click on the form's title the form is restored. how can i disable this
2. If use this for when the zoomed image doesn't have scrollbars
3. it is posibile to make the form full screen?
form borderstyle:=bsSingle
Window State:= wsMaximized
autoscroll:=true
I've chanced my mind and i want to stay the form all the time maximized, but i have 3 pb:
1. when i double click on the form's title the form is restored. how can i disable this
2. If use this for when the zoomed image doesn't have scrollbars
3. it is posibile to make the form full screen?
Free VCL with source code
http://www.torry.net/quicksearchd.php?String=TMagnify+v.2.0&Title=Yes
http://www.torry.net/quicksearchd.php?String=TMagnify+v.2.0&Title=Yes
ASKER
esoftbg if you can tell me how can i view the image in full screen youl make me happy:)
Thanks
Thanks
procedure ImageBestFit(Image: TImage);
var
H: Integer;
W: Integer;
IHeight:Integer;
IWidth: Integer;
DH: Double;
DW: Double;
D: Double;
begin
D := 1;
Image.Top := 0;
Image.Left := 0;
try
(Image.Owner as TForm).Align := alClient;
IHeight := (Image.Parent as TWinControl).Height;
IWidth := (Image.Parent as TWinControl).Width;
H := Image.Picture.Bitmap.Heigh t;
W := Image.Picture.Bitmap.Width ;
DH := IHeight / H;
DW := IWidth / W;
if (H<>IHeight) or (W<>IWidth) then
begin
Image.Stretch := True;
if (DH<DW) then
D := IHeight/H
else
D := IWidth/W;
end;
finally
Image.Height := Round(D*H);
Image.Width := Round(D*W);
end;
end;
var
H: Integer;
W: Integer;
IHeight:Integer;
IWidth: Integer;
DH: Double;
DW: Double;
D: Double;
begin
D := 1;
Image.Top := 0;
Image.Left := 0;
try
(Image.Owner as TForm).Align := alClient;
IHeight := (Image.Parent as TWinControl).Height;
IWidth := (Image.Parent as TWinControl).Width;
H := Image.Picture.Bitmap.Heigh
W := Image.Picture.Bitmap.Width
DH := IHeight / H;
DW := IWidth / W;
if (H<>IHeight) or (W<>IWidth) then
begin
Image.Stretch := True;
if (DH<DW) then
D := IHeight/H
else
D := IWidth/W;
end;
finally
Image.Height := Round(D*H);
Image.Width := Round(D*W);
end;
end;
ASKER
thank you very much
Regards
Regards
You are welcome !
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ToolWin, ComCtrls, Buttons;
type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
Image1: TImage;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
private{ Private declarations }
public { Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure ResizeImage(Image: TImage; DSize: Double);
var
H: Integer;
W: Integer;
D: Double;
begin
D := DSize/100;
H := Image.Picture.Bitmap.Heigh
W := Image.Picture.Bitmap.Width
Image.Stretch := True;
Image.Align := alNone;
try
DSize := H*DSize/100;
if ((H>DSize) or (W>DSize)) then
begin
Image.Stretch := True;
if (H>W) then
D := DSize/H
else
D := DSize/W;
end;
finally
Image.Height := Round(D*H);
Image.Width := Round(D*W);
end;
end;
procedure TForm1.SpeedButton1Click(S
const
DSize: Double = 200;
begin
ResizeImage(Image1, DSize);
end;
procedure TForm1.SpeedButton2Click(S
const
DSize: Double = 50;
begin
ResizeImage(Image1, DSize);
end;
end.
//........
object Form1: TForm1
Left = 216
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
Left = 0
Top = 25
Width = 153
Height = 139
Picture.Data = {
07544269746D6170E62B000042
00008B00000001000400000000
00000000000000008000008000
C000808080000000FF0000FF00
FF007777777777777777777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
26267777777777777777777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
00007777777777777777778778
77777777777777777777777777
77777777777777777777777777
878878778777404FF8F8F84057
77777777777777777777777777
00007777777777778878787777
77777777777777777777777777
77777777777777777777777777
777778778788450FFFFFFFFF48
7B7B7777777F77777777777777
FFFF7777777778F87777777777
777777F77B7777B77978979838
77777777777777777777777777
77777777777774088F88FFFFF4
8373797B7B777777BF77777777
FFFF7777777878777777777777
77777798381831881838188138
77777777777777777777777777
7777777777777540FFFFFF8F87
3183939B7B897B77B7B7F77777
FFFF7777788777777777777777
77988831818130180312181213
77777777777777777777777777
777777778BBBBB408FFFFFFFF8
13389339B37B8BB7B7B777B777
FFFF77777877777777777BBB77
89818181181212110121812181
77777777777777777777777777
77777777777777840F8888F8F8
13393839B9B7B7B7B777777777
FFFF7778F877777777BB777777
88181101813010813103111213
77777777777777777777777777
777777777777777404FF8F8888
13393938B9BB37BB7B77777777
0F02777877777777BB77777777
88388181812111211810318130
77777777777777777777777777
777777777777777404F88F8888
313893939B8B9B8B97B7777777
444477787777778B7777777777
7B710811381218103118121121
77777777777777777777777777
77777777777777774048888888
318338939B8B8B9B7B77777777
FF007778777777B77777777777
0810B8B1181181821181211213
77777777777777777777777777
77777777777777784404777778
1318338B93737B9B7B77777777
FFFF777877777B777777777777
80101010B37110318181130318
77777777777777777777777777
77777777777777777777777777
13938B8339B8B89B7B77777777
FFFF777878777B777777777777
2110180121183B810818180131
77777777777777777777777777
77777777777777777777777777
31339379B3B9B97BB7B7777777
FFFF777787778B777777777777
7771030112111181B813098031
77777777777777777777777777
77777777777777777777777777
13839B9739B73B97B777777777
FFFF77778777BB777777777777
7777777130108118103B811818
77777777777777777777777777
77777777777777777777777777
183939B9B8B97B7B9B77777777
260F777778777B777777777777
77777777730301111311017391
77777777777777777777777777
77777777777777777777777777
18339373B79B8B8B97BF777777
000F777778777B777777777777
77777777712121101318110818
77777777777777777777777777
77777777777777777777777777
31313839B97B8B7B7B77777777
0000777777877B777777777777
77777777701218121130130131
77777777777777777777777777
77777777777777777777777777
38398318397373B7B7B7777777
FFFF7777777877B77777777777
77777777710103118113839393
77777777777777777777777777
77777777777777777777777777
8B93889383337B37B7B7F77777
FFFF7777777787B87777777777
77777777731810812133138313
77777777777777777777777777
77777777777777777777777777
138B89883933373B7977777777
FFFF7777777778FB7777777777
77777777771121318121301318
77777777777777777777777777
77777777777777777777777777
383938B98983833587B7404404
FFFF77777777778FB777777777
77777777771131803012103031
77777777777777777777777777
77777777777777777777777777
B7B9393789B838937B4877FF7F
FFFF777777777778FB77777777
7777777777713103010301831B
78777777777777777777777777
77777777777777777777777777
77B9B3739B8B8983334085047F
FF007777777777778FB7777777
77777777773013110813833B7B
87877787777777777777777777
77777777777777777777777777
B97B8B83339873794838B77FF0
0FFF777777777777778B777777
77777777713108112111813338
F8777777777777777777777777
77777777777777777777777777
B93833833339897405389B77FF
FFFF7777777777777778B77777
77777777313011181801301210
F8777777777777777777777777
77777777777777777777777777
9338181313839734807979B7FF
BFBF77777777777777778B7777
77777778131010113011311313
88888788787777777777777777
87787787777777777777777777
1181308313389B3B41787977FF
FFFF777777777777777787BB8F
777777830181130101813338B7
8F877777777777777777777777
87887877777777777777777777
31811303838393738417B877BF
FFFF777777777777777778FBB8
77777712101211301101081010
77777777777777777777777777
8F88F877787777777777777777
8131310318339B8B7340B7B877
FFFF777777777777778778888B
77777130103081318311313113
77777777777777777777777777
8F88F887777777777777777777
1311813839373B8B7B7848B978
0000777777777777778788F888
7777310810121811030313877F
77777777777777777777777777
8888F878777777777777777777
3131318338B8B9B7B7B7B97040
FFFF777777777777778F8F88F8
7778131210101211013108137B
77777777777777777777777777
BFBFF888B77777777777777777
8313131337B37B97B7B7B7B9B8
FFFF777777777777778F88F88F
77710118030101010112110181
77777777777777777777777777
BFF8778B778777777777777777
31313139B8BB89B7B77B7B7B97
777777777777777777778F8F88
77710181018010910111311311
81877777777777777777777777
78778778B77777777777777777
33183939B37B97BB7B77B7B7B8
FFFF7777777777777777788F88
7731031080121810139B7FFFFF
88989897977777777777777777
787778787B7787777777777777
3933893973B8B7B7B777BFB77B
FFFF7777777777777777787878
771308101081031813B7FFFFFF
3B8101017B7777777777777777
B777787B7B7787777777777777
39B389B8B97B7B7B7777F7FB7B
FFFF777777777777777777877B
1810121001018031838FFFFFFF
B87B397BFBFBFBB7777777B777
777B778F88B787777777777777
B9B8B8B8B7B77B7F7FF7F7F7BB
FFFF7777777777777777777778
3112101010801081383FFFF7F7
3038837B7F7FB7777777777B77
77778B77787B77777777777777
8B8B8B8B7BB777BF7F7FF77777
FFF47777777777777777777777
13018101210180011397FFFBFF
131BB83B7B7B7777777777B777
888778BF887777777777777777
9833337B97BF7F7FF7F7F7BBBB
FF447777777777777777777777
8103108010101010393BFFFF77
BB38181833181B7777777B7777
BFBF8FB7777777777777777777
8121131837BFFFFFFFB7F7FB7B
FFFF7777777777777777777777
0318031018121101318B7FBF7B
318139837B339337777B777777
77777777777777777777777777
318103739B77F7B77FB7FBF7B8
FFFF7777777777777777777777
01303081301801018138B77B7B
8B931389B83713BB7B77777777
77777777777777777777777777
13121318338313138B9B77B7BB
FFFF7777777777777777777777
030131218010101103138B7733
B9113318108B13BB77BB777777
77777777777777777777777777
13103181281138933937FBBB38
FFFF7777777777777777777777
3103131301010108113183B398
B79739373897B97777777BB777
77777777777777777777777777
383383308313B79B837F7BB9B3
44FF7777777777777777777777
10313181010101121091393331
180138777B878B7777777777B7
77777777777777777777777777
213130338B33931B7FFB7B9383
F4447777777777777777777777
21081103011081180131383331
B1331B33837378B77777777777
77777777777777777777777777
313130981393FFFFFFB7938311
FFFF7777777777777777777777
12110181318110312131839393
9BB3B337B89B77BFB777777777
77777777777777777777777777
379B7B7FBFF7FFF7F7B7391317
FFFF7777777777777777777777
31180103181310318131331393
B7BFFFB79BBBB77F7FB77777BB
77777777777777777777777778
777B7BFBF7F7FFFF77BBB9133B
FFFF7777777777777777777777
18113031101811812133183939
9313B37F77FF77FFF7B7777777
77777777777777777777777773
777B7BFBFFBFFFF7BB83397FFF
FFFF7777777777777777777777
10981030310112131318138339
7F77BBFFF7F77F77B777777777
77777777777777777777777770
B777BF7BF7F7BF7B9B7BB9BBBB
FFFF7777777777777777777777
1110301031031018138138339B
39BB839B7FFFFFF8B777777777
77777777777777777777777778
7B77B7777BF7B9B77393137B7F
F0027777777777777777777777
01010310811031813183983398
13FFF7FF7BF77BF8B777777777
77777777777777777777777777
797B7B777B739B931383393931
FFFF7777777777777777777777
101211031111218131813893B9
7F139338FFBBBBBB7777777777
77777777777777777777777777
7B7B7B7B8138139FFFF7B7B9B9
FF0F7777777777777777777777
10108010118113038393389379
F1397777F7FFFF787777777777
77777777777777777777777777
73118313381BF7B7FF7FBFFFFF
FFF77777777777777777777777
0181218011011313393837379B
7FF7FFFFFFF7FF877777777777
77777777777777777777777777
18131837FF7FF79339BFFFF7B7
FFFF7777777777777777777777
1001803101801313133938B8B7
77FFFFF77FFFFC877777777777
77777777777777777777777777
11813377F98388F89377F7FF7F
FFFF7777777777777777777777
1801031810308101383B938383
FFFFFFFF7FFF87777777777777
77777777777777777777777777
81337393313FF17F7F7F7B7797
FFFF7777777777777777777777
1211031303131811383B831301
FFFFFFFFFF8877777777777777
77777777777777777777777777
39B7787F404041B9B87FFFFFF7
260F7777777777777777777777
7308121393810138BB7B930113
FFFF7FFF887777777777777777
77777777777777777777777777
3777F04797777F408FFFFFFF77
00007777777777777777777777
7703083131033BB37B77739371
FFC88877777777777777777777
77777777777777777777777777
777777577779FFF4078888888C
99BB7777777777777777777777
777121393981313937FF7B139F
F7777777777777777777777777
77777777777777777777777777
377FF7F777F77750477FFFFFFF
0FFF7777777777777777777777
777718133130137B77BFFF7111
77777777777777777777777777
77777777777777777777777777
FFFF7FF77F7F84048F777FFFFF
FFFF7777777777777777777777
77777731833777B7FFF7FFFB7F
77777777777777777777777777
77777777777777777777777777
FFFF7FF7F774040777FFF7FFFF
FFFF7777777777777777777777
77777777393938B7B7B7777BFF
77777777777777777777777777
77777777777777777777777777
7F7F7F7774408F7F7F7F7F7777
FFFF7777777777777777777777
7777777777B93739B7B7BF7FBF
77777777777777777777777777
77777777777777777777777777
77777777414F777777777777B7
FFFF7777777777777777777777
77777777777777B7B7B7B7F777
77777777777777777777777777
77777777777777777777777777
77777777740777777707777777
DCCC7777777777777777777777
77777777777777777777B77777
77777777777777777777777777
77777777777777777777777777
777777F7F70477770447777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
77777777777777777777777777
00007777777777777777777777
77777777777777777777777777
77777777777777777777777777
Stretch = True
end
object CoolBar1: TCoolBar
Left = 0
Top = 0
Width = 688
Height = 25
Bands = <>
object SpeedButton1: TSpeedButton
Left = 1
Top = 1
Width = 64
Height = 22
Caption = '200 %'
OnClick = SpeedButton1Click
end
object SpeedButton2: TSpeedButton
Left = 66
Top = 1
Width = 79
Height = 22
Caption = '50 %'
OnClick = SpeedButton2Click
end
end
end