problem with printing barcode [modified]
-
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
-
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
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 -
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
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 SubPublic 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.
-
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 SubPublic 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.