Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. problem with printing barcode [modified]

problem with printing barcode [modified]

Scheduled Pinned Locked Moved Visual Basic
graphicshelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sipder
    wrote on last edited by
    #1

    I am using barcode image of type bitmap and have assiged to picturebox. The original image size is larger than picturebox size, so i have used the property "Sizemode=stretch" because i want the image to be displayed in picturebox size. after doing so and trying to print the form, the quality of image present in picturebox comes out very poor,the lines of barcode look like they have got mixed with each other,image is distorted . if i increase the size of picturebox, print is very clear, but i need to print image in small size. may i know some solution?

    modified on Saturday, November 8, 2008 9:27 AM

    D S 2 Replies Last reply
    0
    • S Sipder

      I am using barcode image of type bitmap and have assiged to picturebox. The original image size is larger than picturebox size, so i have used the property "Sizemode=stretch" because i want the image to be displayed in picturebox size. after doing so and trying to print the form, the quality of image present in picturebox comes out very poor,the lines of barcode look like they have got mixed with each other,image is distorted . if i increase the size of picturebox, print is very clear, but i need to print image in small size. may i know some solution?

      modified on Saturday, November 8, 2008 9:27 AM

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      What's the component you're using to generate the barcode image?? Does this component let you specifiy the size of the image you want?? If not, I suggest looking for another component.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      • S Sipder

        I am using barcode image of type bitmap and have assiged to picturebox. The original image size is larger than picturebox size, so i have used the property "Sizemode=stretch" because i want the image to be displayed in picturebox size. after doing so and trying to print the form, the quality of image present in picturebox comes out very poor,the lines of barcode look like they have got mixed with each other,image is distorted . if i increase the size of picturebox, print is very clear, but i need to print image in small size. may i know some solution?

        modified on Saturday, November 8, 2008 9:27 AM

        S Offline
        S Offline
        sph3rex
        wrote on last edited by
        #3

        Probably that`s because the bitmap you`re loading has a different aspect ratio from the picture box ur fitting it into. Stretch means that the image will fill the container, so it your picture box has a size like Width:200, Height:150 and the barcode has let`s say Width: 100, Height: 120 it will appear disproportioned in the picture box. One way to get around this would be this:

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _hW As Single = Me.PictureBox1.Image.Width
        Dim _hH As Single = Me.PictureBox1.Image.Height
        Dim ratio As Single = IIf(_hW >= _hH, _hW / _hH, _hH / _hW)
        'resize image according to which is the highest ... Width or Height
        If (_hW > _hH) Then
        Me.PictureBox1.Image = ResizeImg(Me.PictureBox1.Image, New Size(Me.PictureBox1.Width, Me.PictureBox1.Width / ratio))
        Else
        Me.PictureBox1.Image = ResizeImg(Me.PictureBox1.Image, New Size(Me.PictureBox1.Height / ratio, Me.PictureBox1.Height))
        End If
        End Sub

        Public Function ResizeImg(ByVal img As Image, ByVal size As Size) As Image
            Dim bm As Bitmap = New Bitmap(img, Convert.ToUInt32(size.Width), Convert.ToUInt32(size.Height))
            Dim myNewImage As Graphics = Graphics.FromImage(bm)
            myNewImage.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
            Return bm
        End Function
        

        The above code assumes that the barcode image is loaded in the picturebox at runtime. You can modify the code to fit ur exact needs moving the Form1_Load code to the place in code where u need it. If the program that generates your barcodes allows it, try increasing the HEIGHT of the bars to fit into the picture boxes aspect ratio.

        S 1 Reply Last reply
        0
        • S sph3rex

          Probably that`s because the bitmap you`re loading has a different aspect ratio from the picture box ur fitting it into. Stretch means that the image will fill the container, so it your picture box has a size like Width:200, Height:150 and the barcode has let`s say Width: 100, Height: 120 it will appear disproportioned in the picture box. One way to get around this would be this:

          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          Dim _hW As Single = Me.PictureBox1.Image.Width
          Dim _hH As Single = Me.PictureBox1.Image.Height
          Dim ratio As Single = IIf(_hW >= _hH, _hW / _hH, _hH / _hW)
          'resize image according to which is the highest ... Width or Height
          If (_hW > _hH) Then
          Me.PictureBox1.Image = ResizeImg(Me.PictureBox1.Image, New Size(Me.PictureBox1.Width, Me.PictureBox1.Width / ratio))
          Else
          Me.PictureBox1.Image = ResizeImg(Me.PictureBox1.Image, New Size(Me.PictureBox1.Height / ratio, Me.PictureBox1.Height))
          End If
          End Sub

          Public Function ResizeImg(ByVal img As Image, ByVal size As Size) As Image
              Dim bm As Bitmap = New Bitmap(img, Convert.ToUInt32(size.Width), Convert.ToUInt32(size.Height))
              Dim myNewImage As Graphics = Graphics.FromImage(bm)
              myNewImage.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
              Return bm
          End Function
          

          The above code assumes that the barcode image is loaded in the picturebox at runtime. You can modify the code to fit ur exact needs moving the Form1_Load code to the place in code where u need it. If the program that generates your barcodes allows it, try increasing the HEIGHT of the bars to fit into the picture boxes aspect ratio.

          S Offline
          S Offline
          Sipder
          wrote on last edited by
          #4

          I tried the code you have given but the image is still not clear. Can this happen beacause of Virus? My system is badly infected.

          modified on Sunday, November 9, 2008 11:41 PM

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups