By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Displaying images in a picture box

P: n/a
I am trying to display an image in a picture box. The image is a group 4 fax
black and white image of a piece of sheet music. The original resolution is
300 X 300 dpi. I want to have the picture box as large as possible so I can
view the scanned image on my computer screen. At run time, I want to be able
to view different files by changing the image file name property.

I thought the picture box could be setup so that the image would be
stretched or compressed to fit inside the picture box but I have not been
able to do so. It seems that the imageis to large for the picture box.
Perhaps I am not using the picture box options correctly.

So my question is..Is this the right control for this task, and if so, what
am I doing wrong?
Nov 21 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
try setting the picturebox sizemode to "stretch image", see if that does what
you want

-iwdu
Nov 21 '05 #2

P: n/a
try setting the picturebox sizemode to "stretch image", see if that does what
you want

-iwdu
Nov 21 '05 #3

P: n/a
I tried that. It seems that stretch seems to work but if the image is
already to large, it won't reduce the image. I am thinking I might have to
something more complicated like using the greaphics or image class methods to
resize and/or resample the image. I am out of my element here I think.


"iwdu15" wrote:
try setting the picturebox sizemode to "stretch image", see if that does what
you want

-iwdu

Nov 21 '05 #4

P: n/a
I tried that. It seems that stretch seems to work but if the image is
already to large, it won't reduce the image. I am thinking I might have to
something more complicated like using the greaphics or image class methods to
resize and/or resample the image. I am out of my element here I think.


"iwdu15" wrote:
try setting the picturebox sizemode to "stretch image", see if that does what
you want

-iwdu

Nov 21 '05 #5

P: n/a
Hamil,

You ask in my opinion two things in one time. You want to stretch the image
and keep it original and when it does not fit on a window you want to resize
it. (and than probably inside the original rectangle values). The last you
have to do at the bitmpap. See for that Bop Powell pages.

http://www.bobpowell.net/

I hope this helps,

Cor
Nov 21 '05 #6

P: n/a
Hamil,

You ask in my opinion two things in one time. You want to stretch the image
and keep it original and when it does not fit on a window you want to resize
it. (and than probably inside the original rectangle values). The last you
have to do at the bitmpap. See for that Bop Powell pages.

http://www.bobpowell.net/

I hope this helps,

Cor
Nov 21 '05 #7

P: n/a
The image I want to display is a 8-1/2 X 11 inch page. At 300 DPI, my scan
resolution, I have a pixel dimension of 2550 X 3300 pixels. Lets say my
picture box is sized for say 637 X 825 pixels. When I set the picturebox
image property to the tif file, only a small part of my page is displayed. So
I am wondering what I should do to make my tif page display inside my picture
box.

I know that the picture box has a stretch property that will expand a small
image to 3) fill the picture box, but it doesn't have a property to shrink
the image to fit inside the box. I don't think.

I am wondering if I will have to do something more complicated like ..

1) create a graphic image object
2) input the tif file into the graphic object
use some sort of method to resize and resample the image to make it fit
inside the picture box.
4) set the picture box image property to this graphic object.

What do you think?

Hamil.


"Cor Ligthert [MVP]" wrote:
Hamil,

You ask in my opinion two things in one time. You want to stretch the image
and keep it original and when it does not fit on a window you want to resize
it. (and than probably inside the original rectangle values). The last you
have to do at the bitmpap. See for that Bop Powell pages.

http://www.bobpowell.net/

I hope this helps,

Cor

Nov 21 '05 #8

P: n/a
Hamil,

There are a lot of functions, however only the strech does not have impact
on the shape.

If you want to make in smaller keeping the shape the same, than you have to
use the graphic functions for that.

If that is necessary. I cannot see the importancy of this for you

However have a look at that page from Bob, AFAIK has he samples for that.
Cor
Nov 21 '05 #9

P: n/a
Cor,.. I went to Bobs site as you suggested. His example under imaging is
very close to what I want so I entered his code and tried it (the code
listiong is below). However, the code would not compile. I get the following
error messages..

error 1
C:\_p\TifDisplayProject\TifDisplayProject\Form1.vb (18): Method 'New' has
multiple definitions with identical signatures.

error2
'Sub Main' was not found in 'TifDisplayProject.Form1'.
Also, he is doing a few tricks I don't understand. For example the code..

<STAThread()> _
Shared Sub Main
Application.Run(New Form1())
End Sub

Why is he doing this??

If I can get this example to work, I think I will be OK.

I appreciate your help.

Hamil.

******** Code follows ********

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data

Namespace drawimage1
'/ <summary>
'/ Summary description for Form1.
'/ </summary>

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(544, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(16, 16)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(576, 421)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private MyImage As Image

Public Sub New()
End Sub 'New

'/ <summary>
'/ The main entry point for the application.
'/ </summary>
<STAThread()> _
Shared Sub Main()
Application.Run(New Form1)
End Sub 'Main

Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyImage = Image.FromFile("C:\temp\Tif1.tif")
MyBase.OnLoad(e)
End Sub 'OnLoad

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If Not (MyImage Is Nothing) Then
e.Graphics.DrawImage(MyImage, 0, 0)
End If
MyBase.OnPaint(e)
End Sub 'OnPaint

End Class 'Form1
End Namespace 'drawimage1
"Cor Ligthert [MVP]" wrote:
Hamil,

There are a lot of functions, however only the strech does not have impact
on the shape.

If you want to make in smaller keeping the shape the same, than you have to
use the graphic functions for that.

If that is necessary. I cannot see the importancy of this for you

However have a look at that page from Bob, AFAIK has he samples for that.
Cor

Nov 21 '05 #10

P: n/a
Hamil,

<STAThread()> _
Shared Sub Main
Application.Run(New Form1())
End Sub

Why is he doing this??

I have made a new sample, however. This is a kind of using the same method
as C# does it STAT mean static appartment model. In VBNet is this build in
in the mainform. If you use this than you have to set in your properties
that Sub Main is the startup object.

Because in my opinion the sample you gave me did not do what you asked (it
draws a bitmap on a screen), have I made a little dirty sample myselfs (it
works). You have yourself make the resizing accoording to your form/imagebox
format.

http://www.windowsformsdatagridhelp....c-fd5823b51f41

I hope this helps,

Cor
Nov 21 '05 #11

P: n/a
Oeps,

STA single treaded apartment

http://msdn.microsoft.com/library/de...classtopic.asp

Cor
Nov 21 '05 #12

P: n/a
YES! I tried your code, IT WORKS!

I am getting the picture now (no pun intended). One last question...I hope.

When I open my original tif document using a viewer, such as Irfanview, the
image is very clear, in that the jagged edges are cleaned up. My input file
is a scanned page of sheet music with horizontal lines. Obviously, Irfanview
does some kind of resampling or filtering when they reduce the pixel
dimension of the tif page.

When the DrawImage is performed in your routine, it seems that no resampling
or or filtering is taking place. What happens is that there are gaps in the
horizontal lines. I suspect that there is a method that can be used to
perform the resizing in a better manner. Perhaps the DrawImage method merely
takes every third pixel for example while a better resizing would do a better
job perhaps by taking three pixels , doing an average, or something like that.

I see tht there are some converter routines available but I don't know which
one to use or how to do so. I would think that the code would be something
like...

MyImage = image.fromfile("C:\myfile.tif")
ReducedImage = MyImage.resample(ReductionPercentage)
graphics.drawimage ReducedImage

What do you think??

Hamil.





"Cor Ligthert [MVP]" wrote:
Hamil,

<STAThread()> _
Shared Sub Main
Application.Run(New Form1())
End Sub

Why is he doing this??

I have made a new sample, however. This is a kind of using the same method
as C# does it STAT mean static appartment model. In VBNet is this build in
in the mainform. If you use this than you have to set in your properties
that Sub Main is the startup object.

Because in my opinion the sample you gave me did not do what you asked (it
draws a bitmap on a screen), have I made a little dirty sample myselfs (it
works). You have yourself make the resizing accoording to your form/imagebox
format.

http://www.windowsformsdatagridhelp....c-fd5823b51f41

I hope this helps,

Cor

Nov 21 '05 #13

P: n/a
Hamil,

Look on our page, this was a very simple sample. Peter Proost gave a new
more extended one. Maybe you can try that as well.

http://www.windowsformsdatagridhelp....5-3479119c0d1c

Cor
Nov 21 '05 #14

P: n/a
Thank you! This is exactly what I was looking for. The jaggies are filtered
out by the more advanced interpolation filter. I will now spend some time
learning all the details of *how* this works now that I have a good example.
Thanks again for your help

Haml.
"Cor Ligthert [MVP]" wrote:
Hamil,

Look on our page, this was a very simple sample. Peter Proost gave a new
more extended one. Maybe you can try that as well.

http://www.windowsformsdatagridhelp....5-3479119c0d1c

Cor

Nov 21 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.