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

Image resizing after resolution adjustment.

P: n/a
Hello all,

I am working with some barcode images using a TTF (True Type Font). I know
it is not the best method, but it is what I have available at the moment. I
have everything working all up to printing the barcode to an image file, I
have code that works for that but the resolution is far too low for
recognition from a barcode scanner

The form I have contains a textbox, label, and 2 buttons. The textbox is the
input section, label is the output, button1 is the convert event button2 is
the print function.

How it runs.

Enter text to convert and hit button1. Button1 coverts to proper a code39
barcode string, send string to label and change label font to code39.
Instant Barcode.

Hit button2 and pass to the function the labels string, PreferredWidth,
PreferredHeight, and FileName.

This creates 2 image files of the perfect size and they look decent, but with
too low a resolution to be read by a barcode scanner. I have attempted to
fix this by adding the code line:

img.SetResolution(300, 200)

after

' Create a blank image.
img = New System.Drawing.Bitmap( _
intWidt + 15, _
intHeight + 20, _
System.Drawing.Imaging.PixelFormat.Format32bppRgb _
)

But I cannot figure a way to resize the image to make it the right size like
the function without that code line in it. Does anyone have any ideas?

Current Image Function code prints a barcode(works but resolution too low).

Private Function Print_Images(ByVal strData As String, ByVal strFont As
String, ByVal intWidth As Integer, ByVal intHeight As Integer, ByVal
strFileName As String)
Dim img As System.Drawing.Bitmap
Dim canvas As System.Drawing.Graphics = Nothing

' Create a blank image.
img = New System.Drawing.Bitmap( _
intWidt + 15, _
intHeight + 20, _
System.Drawing.Imaging.PixelFormat.Format32bppRgb _
)
Try
' Create the canvas.
canvas = System.Drawing.Graphics.FromImage(img)

' Paint a background.
canvas.Clear(System.Drawing.Color.White)

' Draw the string.
canvas.DrawString( _
strData, _
New System.Drawing.Font(strFont, 28), _
System.Drawing.Brushes.Black, _
10, _
10 _
)

' Save the image to disk.
img.Save( _
"C:\Images\" & strFileName & ".jpg", _
System.Drawing.Imaging.ImageFormat.Jpeg _
)
img.Save( _
"C:\Images\" & strFileName & ".bmp", _
System.Drawing.Imaging.ImageFormat.Bmp _
)
Finally
' Cleanup.
If Not canvas Is Nothing Then
canvas.Dispose()
End If
img.Dispose()
End Try

Return (Nothing)
End Function

--
Message posted via http://www.dotnetmonster.com

Nov 17 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.