From: Viper900 on
What is the best way to resize pictures so that they fit in the imagebox,
placed on the form. I have the image names in a listbox and when i click on
the image it is displayed in the imagebox, however, you can only see part of
the larger images.
Thanks
From: C. Kevin Provance on

"Viper900" <Viper900(a)discussions.microsoft.com> wrote in message
news:C38BC369-9B38-40F2-93EF-474C349862BF(a)microsoft.com...
: What is the best way to resize pictures so that they fit in the imagebox,
: placed on the form. I have the image names in a listbox and when i click
on
: the image it is displayed in the imagebox, however, you can only see part
of
: the larger images.
: Thanks

Google for GDI+ wrapper and use that. You can specify image sizes when
displaying them. That's what I do anyways. Someone else might have
something easier.


--
Customer Hatred Knows No Bounds at MSFT
Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc

Bawwk! Paulie want a dingleball, bawwk!

From: Rick Rothstein on
> What is the best way to resize pictures so that they fit in the imagebox,
> placed on the form. I have the image names in a listbox and when i click
> on
> the image it is displayed in the imagebox, however, you can only see part
> of
> the larger images.
> Thanks

Perhaps the following (real) old posting of mine will be of some help. What
the subroutine does is fit a picture to the display container while
maintaining the pictures aspect ratio.
--
Rick (MVP - Excel)

You will need to put your picture into an ImageBox and place that ImageBox
onto your Form. Then give the following Subroutine a try. It properly fits
the ImageBox (with its Stretch property set to False) into its container (in
this case, the Form, but it would also work if the container was a Frame, a
PictureBox or anything else that can serve as a container). So, for your
program, use a Form of whatever size you need as a container for the
ImageBox.

The first parameter is the name you have given to the ImageBox. The optional
2nd argument allows you to specify a minimum number of pixel that the image
must be away from the closest edge of its container. As an example, you
could call the following subroutine like this (assuming you place a
CommonDialogBox on your form; otherwise, just specify the path/filename, by
whatever means you obtain it, as the argument to the LoadPicture
function)...

CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
SetImageBoxSize Image1, 150

where your ImageBox is named Image1 and the picture won't come any closer
than 150 twips to an edge of its Container. Simply assign your picture to
the ImageBox control and call this subroutine.

Private Sub SetImageBoxSize(ImageBox As Image, _
Optional ImageReductionAmount As Long = 0)
Dim ParentRatio As Single
Dim PictureRatio As Single
Dim ContainerWidth As Single
Dim ContainerHeight As Single
Dim ContainerControl As Control
With ImageBox
.Visible = False
.Stretch = False
PictureRatio = .Width / .Height
On Error Resume Next
ContainerWidth = .Container.ScaleWidth
If Err.Number Then
ContainerWidth = .Container.Width
ContainerHeight = .Container.Height
Else
ContainerHeight = .Container.ScaleHeight
End If
ParentRatio = ContainerWidth / ContainerHeight
If ParentRatio < PictureRatio Then
.Width = ContainerWidth - 2 * ImageReductionAmount
.Height = .Width / PictureRatio
Else
.Height = ContainerHeight - 2 * ImageReductionAmount
.Width = .Height * PictureRatio
End If
.Stretch = True
.Move (ContainerWidth - .Width) \ 2, _
(ContainerHeight - .Height) \ 2
.Visible = True
End With
End Sub


From: Larry Serflaten on

"Viper900" <Viper900(a)discussions.microsoft.com> wrote
> What is the best way to resize pictures so that they fit in the imagebox,
> placed on the form. I have the image names in a listbox and when i click on
> the image it is displayed in the imagebox, however, you can only see part of
> the larger images.
> Thanks

ImageBox? Where did you get that control?

If its just for display, use an Image control with its Stretch property set so
that the image shrinks to fit in your display area. If you want to keep the
aspect ratio, Use the picture's Width and Height to calculate the appropreate
values for the Image control....

If you need to draw on the image, then you'll have to paint in on a PictureBox.

LFS


From: Saga on
Thanks Rick! I am about to start a project where I need to display an image
on screen and this routine will be very helpful. Regards, Saga


 |  Next  |  Last
Pages: 1 2
Prev: Forms and Controls
Next: TypeOf