Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
senna  
#1 Posted : Tuesday, October 19, 2004 5:09:00 AM(UTC)
senna

Rank: Member

Groups: Member
Joined: 10/19/2004(UTC)
Posts: 4

Hi,

I would to know if there is any possibility to adjust the width of the image to the control (and not the height to the control --> autozoom), so that the width is on its maximum. It can be easier for reading Text Pages, ... the only thing you've to do is to scroll down to read the rest of the document. (no need to scroll left or right).

The reason I'm asking this is that the autozoom is too small to read some kind of documents like Text pages.

Thanks a lot

Davy.

jvv  
#2 Posted : Wednesday, October 20, 2004 5:41:00 PM(UTC)
jvv

Rank: Member

Groups: Member
Joined: 10/14/2004(UTC)
Posts: 37

In Delphi I divide the width of the control with the width of the image.

If you get a scrollbar, you can use as width of the control: the width of the control - the width of the vertical scrollbar.

Tomorrow, when I'm at my work, I can post a code snippet...

Andrew  
#3 Posted : Wednesday, October 20, 2004 11:09:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Thank you for your input. Just want to add that you should also take into account width of the control border (unless you have BorderStyle = none).

Another notice, the best location to put control resizing is AfterChange event. It allows you to avoid "copy-paste" if you load file from several locations.

Code:
Option Explicit
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Const SM_CXVSCROLL = 2

Private Sub BitmapViewer1_AfterChange(ByVal changeDescription As String, ByVal changeID As Long)
    If changeID = GraphicsMillConstants.GraphicsMillBitmapChangeLoad Then
        BitmapViewer1.ZoomQuality = ZoomQualityHigh
        BitmapViewer1.Zoom = (BitmapViewer1.Width - GetSystemMetrics(SM_CXVSCROLL) - 2) / BitmapViewer1.Bitmap.Data.Width
    End If
End Sub

Private Sub Command1_Click()
    If FileDialog1.ShowOpen Then
        BitmapViewer1.Bitmap.LoadFromFile FileDialog1.FileName
    End If
End Sub

Several comments:

  • To get this sample working, just create empty project and drop one button, one BitmapViewer, and one FileDialog.

  • To get scroll width, I imported WinAPI function GetSystemMetrics. When you pass SM_CXVSCROLL constant, it returns width of the vertical scroll bar.

  • By default BitmapViewer has BorderStyle = BorderStyleEtched. It reduces the visible area at 2 pixels. So we should also subtract it. Unfortunately I have not found a function which would calculate border size, but if you like, I can ask the developers.

  • Note, in AfterChange event handler I take a look whether changeID equals to GraphicsMillBitmapChangeLoad constant. I made it to avoid zoom change when some other modification to image is done (because user can zoom in/out it manually). You can extend this condition if you need to update after resize/crop/some other transform which changes image size.

Please let me know if you have any problems with it.

Edited by user Monday, December 24, 2007 4:41:28 PM(UTC)  | Reason: Not specified

jvv  
#4 Posted : Thursday, October 21, 2004 3:11:00 PM(UTC)
jvv

Rank: Member

Groups: Member
Joined: 10/14/2004(UTC)
Posts: 37

In Delphi I have the following code for fit width:

Code:
procedure TMainForm.FitWidth();
begin
  TiffViewer.Zoom := (TiffViewer.Width - 20) / TiffViewer.Bitmap.Data.Width;
end;

and the following for fit height:

Code:
procedure TMainForm.FitHeigth();
begin
  TiffViewer.Zoom := (TiffViewer.Height - 20) / TiffViewer.Bitmap.Data.Height;
end;

Where TiffViewer is an object of the type TBitmapViewer

Edited by user Monday, December 24, 2007 4:41:52 PM(UTC)  | Reason: Not specified

senna  
#5 Posted : Thursday, October 21, 2004 6:02:00 PM(UTC)
senna

Rank: Member

Groups: Member
Joined: 10/19/2004(UTC)
Posts: 4

Thanks a lot!!!!

Davy.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.