Recent

Author Topic: How to zoom Image in TImage  (Read 8232 times)

heejit

  • Full Member
  • ***
  • Posts: 245
How to zoom Image in TImage
« on: March 14, 2018, 09:14:17 pm »
I am using scrollbox to display Image various
image from database.

Image size are different size some are large
then the screen.

I want to zoom the image.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: How to zoom Image in TImage
« Reply #1 on: March 14, 2018, 10:05:44 pm »
When you say ZOOM, is that Zoom in or Zoom out?

 There is many ways to interpret that?

 For some ideas

 The Canvas.StretchDraw wil force the image to fit the Rectangle size you give it..

 This includes making the image larger if need or smaller..

  other zooms are for large images where you want to move around inside the image, that would
require you to do a CopyRect, specifying the starting Lift, Top point of the source "The image" and
the direct it to the scrollbox.canvas.

 It would be better if you could give some more clues on how you would like this to zoom?
The only true wisdom is knowing you know nothing

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #2 on: March 14, 2018, 11:03:58 pm »
I want user to ZOOM IN so they can view the image without scrolling

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to zoom Image in TImage
« Reply #3 on: March 14, 2018, 11:36:09 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Image1PictureChanged(Sender :TObject);
  2. begin
  3.   //
  4.   if (Image1.Picture.Graphic.Width > Image1.Width) or (Image1.Picture.Graphic.Height > Image1.Height) then begin
  5.     Image1.Stretch := True;
  6.     Image1.Proportional := True;
  7.   end else begin
  8.     Image1.Stretch := False;
  9.     Image1.Proportional := False;
  10.   end;
  11. end;
  12.  
or simply run the code after the image is loaded.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #4 on: March 15, 2018, 10:25:30 am »
It working but image size is small not visible is there any way
we can set image size to FIT TO FORM SIZE

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to zoom Image in TImage
« Reply #5 on: March 15, 2018, 10:38:54 am »
Code: Pascal  [Select][+][-]
  1. image1.Align := alclient;
  2.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #6 on: March 15, 2018, 11:55:19 am »
if i set align properly image size has increase and we need to scroll

How I can set ZOOM LEVEL so user can adjust ZOOM-IN/ZOOM-OUT
as per there requirement.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to zoom Image in TImage
« Reply #7 on: March 15, 2018, 12:09:16 pm »
if i set align properly image size has increase and we need to scroll
You have something else going on. alClient can not resize the timage outside it's containers client area.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #8 on: March 15, 2018, 12:49:52 pm »
Here is my code

Code: Pascal  [Select][+][-]
  1.  
  2. On form create event I am adding timage to scroll box
  3.  self.imgWidget := TImage.Create(self);
  4.  self.ScrollBox1.InsertControl(self.imgWidget);
  5.  
  6. procedure TForm1.FormResize(Sender: TObject);
  7. begin
  8.     self.imgWidget.Width := self.Width - 150;
  9.     self.imgWidget.Height := self.Height - 150;
  10. end;
  11.  
  12. procedure TForm1.display_image();
  13. var
  14.     astream: TStream;
  15.     atext: string;
  16. begin
  17.     if self.m_qry = nil then begin
  18.         ShowMessage('No Rrecord');
  19.         exit;
  20.     end;
  21.  
  22.     if self.m_qry.EOF = True then begin
  23.         ShowMessage('You are at end');
  24.         exit;
  25.     end;
  26.  
  27.     astream := self.m_qry.CreateBlobStream(self.m_qry.FieldByName('file_data'), bmRead);
  28.     self.imgWidget.Picture.LoadFromStream(astream);
  29.     self.imgWidget.Stretch := True;
  30.     self.imgWidget.Proportional := True;
  31.     self.imgWidget.Align:= alClient;
  32.     atext := self.m_qry.FieldByName('file_id').AsString;
  33.     self.imgWidget.Picture.Bitmap.Canvas.TextOut(0, 0, atext);
  34.  
  35.     //Record counter
  36.     self.lblRecords.Caption := self.m_qry.RecNo.ToString + ' / ' + self.m_qry.RecordCount.ToString;
  37. end;
  38.  
  39.  
« Last Edit: March 15, 2018, 12:53:56 pm by jshah »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to zoom Image in TImage
« Reply #9 on: March 15, 2018, 01:01:08 pm »
multiple problems
1) imgWidget is not in the form its inside a scroll box I have no idea why.
2) alClient will resize the image to fill hte scrollbox client area no the forms.
3) the code in formresize is wasting cpu. If everything works as designed then setting the width and height of a component in alClient mode should be ignored if it is not then report a bug.

for further help please provide a complete compilable example.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #10 on: March 15, 2018, 01:29:55 pm »
1. ScrollBox required if user want to Zoom Image he/she can scroll

2. That means alClient will not work with scrollbox

3. form resize removed

I want to user to ZOOM the image if zoomed image is bigger than
the form size then scroll to view it.

balazsszekely

  • Guest
Re: How to zoom Image in TImage
« Reply #11 on: March 15, 2018, 01:42:02 pm »
You should try ATImageBox, I believe it's exactly what are you looking for. You can find a demo folder inside the component, so you can run a few test.

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #12 on: March 15, 2018, 02:06:00 pm »
@GetMem

Yes it is exactly what I am looking for

Only it is slow in zoom in/out
« Last Edit: March 15, 2018, 02:12:59 pm by jshah »

balazsszekely

  • Guest
Re: How to zoom Image in TImage
« Reply #13 on: March 15, 2018, 02:24:38 pm »
Quote
Only it is slow in zoom in/out
I just tested with a 16.7 MB panoramic picture(10891x2197), zooms in/out fast. It's not slower then the built-in "Windows Photo Viewer". What is your configuration? Laz, FPC, OS, widgetset?
« Last Edit: March 15, 2018, 02:27:04 pm by GetMem »

heejit

  • Full Member
  • ***
  • Posts: 245
Re: How to zoom Image in TImage
« Reply #14 on: March 15, 2018, 02:51:17 pm »
Lazarus Version : 1.9.0
FPC : 3.1.1
SVN Revision : 57501
OS : xubuntu 64bit
RAM : 8gb
CPU : i7
widgetset : x86_64-linux-gtk2

 

TinyPortal © 2005-2018