472,378 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Displaying images in a picture box

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
14 5413
try setting the picturebox sizemode to "stretch image", see if that does what
you want

-iwdu
Nov 21 '05 #2
try setting the picturebox sizemode to "stretch image", see if that does what
you want

-iwdu
Nov 21 '05 #3
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
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
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
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
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
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
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
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
Oeps,

STA single treaded apartment

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

Cor
Nov 21 '05 #12
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the...
3
by: Sp33di3 | last post by:
I've been searching and searching for this and there are lots of posts - but very few answers. I have a SQL2000 Database that has jpg images in a table that I want to display in a webpage. I...
7
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application....
4
by: Lindsey Howell | last post by:
Hello, I've encountered a problem when trying to display BLOB images from a SQL database using VB.NET. This is the code which generates the error: Dim mySqlConnection As SqlConnection = New...
0
by: dkalsow | last post by:
Good Afternoon, I need to create a program that will display images, simular to the Microsoft Picture and fax viewer. I created a vb.net app and put a picture box on it. This works fine except...
15
by: Jameson | last post by:
Happy New Year, Everyone! I am trying to figure out how to display a bunch of images (mainly JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a local directory on the system....
8
by: Jon Weston | last post by:
I'm setting up an Access2003 database with pictures. I put a bound ole picture ctrl on a form that's source is the table that contains the pictures and follow ALL the directions for embedding a...
3
by: velu | last post by:
Asp.Net 2 I am trying to display Image from Northwind Database. I ran a queary "SELECT CategoryID, CategoryName, Description, Picture FROM Categories" but the Dataview displayes all the fields...
1
by: blueheelers | last post by:
I have been researching for several hours on the best way to display images in continous forms in Access 2003. For example, I want to display employee name, email, phone, and picture for each...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.