Fit large picture in PictureBox

D

Dick

Hello,

In my application I have a picturebox that must contain previews of picture
files. The picturebox must always have the same size. For small images
that fit, everything is ok.

How can I fit in larger pictures?
(Ideally would be that the picture is centered and fit in the box)

Is this possible with the standard control?
(if not, are there other controls who can do it out there?)

Tia
 
D

Dick

Thanks for the answer, but that doesn't do the trick with pictures that are
larger than the control itself.
The only that works is sizemode 'StretchImage', but then the image is
deformed.
 
C

Cor Ligthert

Dick,

It does a scrollbar will come up in your form when that is, depending on the
setting of course assuming you did not only look to StrechImage.

Cor
 
D

Dick

A scrollbar will come up in you form:
So the control itself is resized I assume (made bigger).

I want the control to be the same size all the time and the image inside
resized with no deformation if that's possible.
 
J

Jorge

Hi Dick
I use the following to resize the image when its too big
to fit in the picturebox.

Dim caminho As String
Dim imagem As Image
Dim vista_reduzida As Image
Dim a As System.Drawing.Image.GetThumbnailImageAbort
Dim b As System.IntPtr

Try
imagem = imagem.FromFile(caminho)

Dim resolucao_V As Single = imagem.Width
Dim resolucao_H As Single = imagem.Height
If resolucao_H > 992 And resolucao_V > 712 Then
vista_reduzida = imagem.GetThumbnailImage(992, 712,
a, b)
Me.PictureBox1.Image = vista_reduzida
Else
Me.PictureBox1.Image = Image.FromFile(caminho)
End If

Catch ex As Exception
MessageBox.Show(ex.Message, "SIGDIN",
MessageBoxButtons.OK, MessageBoxIcon.Error,
MessageBoxDefaultButton.Button3)
End Try

Kind Regards
Jorge
 
D

Dick

I will try it.
Thanks.

Jorge said:
Hi Dick
I use the following to resize the image when its too big
to fit in the picturebox.

Dim caminho As String
Dim imagem As Image
Dim vista_reduzida As Image
Dim a As System.Drawing.Image.GetThumbnailImageAbort
Dim b As System.IntPtr

Try
imagem = imagem.FromFile(caminho)

Dim resolucao_V As Single = imagem.Width
Dim resolucao_H As Single = imagem.Height
If resolucao_H > 992 And resolucao_V > 712 Then
vista_reduzida = imagem.GetThumbnailImage(992, 712,
a, b)
Me.PictureBox1.Image = vista_reduzida
Else
Me.PictureBox1.Image = Image.FromFile(caminho)
End If

Catch ex As Exception
MessageBox.Show(ex.Message, "SIGDIN",
MessageBoxButtons.OK, MessageBoxIcon.Error,
MessageBoxDefaultButton.Button3)
End Try

Kind Regards
Jorge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top