473,383 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 5541
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.