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
> Hamil,
>
[quoted text clipped - 9 lines]
>
> Cor
Cor Ligthert [MVP] - 13 Sep 2005 06:08 GMT
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.com/default.aspx?ID=ca676f42-2760-4ca7-801c-
fd5823b51f41
I hope this helps,
Cor
Cor Ligthert [MVP] - 13 Sep 2005 07:00 GMT
Oeps,
STA single treaded apartment
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemthreadingapartmentstateclasstopic.asp
Cor
hamil - 13 Sep 2005 18:09 GMT
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.
> Hamil,
>
[quoted text clipped - 20 lines]
>
> Cor
Cor Ligthert [MVP] - 13 Sep 2005 18:42 GMT
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.com/default.aspx?ID=8981acf1-5829-44c6-ac65-
3479119c0d1c
Cor
hamil - 13 Sep 2005 22:31 GMT
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.
> Hamil,
>
[quoted text clipped - 4 lines]
>
> Cor