Image resizing after resolution adjustment.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keldair via DotNetMonster.com

    #1

    Image resizing after resolution adjustment.

    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.SetResoluti on(300, 200)

    after

    ' Create a blank image.
    img = New System.Drawing. Bitmap( _
    intWidt + 15, _
    intHeight + 20, _
    System.Drawing. Imaging.PixelFo rmat.Format32bp pRgb _
    )

    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(By Val 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.PixelFo rmat.Format32bp pRgb _
    )


    Try
    ' Create the canvas.
    canvas = System.Drawing. Graphics.FromIm age(img)

    ' Paint a background.
    canvas.Clear(Sy stem.Drawing.Co lor.White)

    ' Draw the string.
    canvas.DrawStri ng( _
    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.ImageFo rmat.Jpeg _
    )
    img.Save( _
    "C:\Images\ " & strFileName & ".bmp", _
    System.Drawing. Imaging.ImageFo rmat.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

Working...