question

ahmedAlie-8738 avatar image
0 Votes"
ahmedAlie-8738 asked JiachenLiMFST-9349 answered

Save the image and the tools inside it

hi

Use the Barcode Library to read and display a barcode with a picture box2.
Use a picture box1 and put the barcode with a picture box2 and label images in the box to write other specifications.
I want to print a large photo box with a barcode image on the inside and on the product label.
I used the following method to display it in print, but the image appears blurry, unclear and of poor quality.

 'event PrintDocument1_PrintPage
    
  Dim Lbl1 As New Bitmap(LAB_SHOPNAME.Width, LAB_SHOPNAME.Height)
             LAB_SHOPNAME.DrawToBitmap(Lbl1, LAB_SHOPNAME.ClientRectangle)
             Dim pic_code As New Bitmap(PIC_linecode.Width, PIC_linecode.Height)
             PIC_linecode.DrawToBitmap(pic_code, PIC_linecode.ClientRectangle)
    
             Dim PB1 As New Bitmap(PIC_ZXing.Image)
             Dim gr1 As Graphics = Graphics.FromImage(PB1)
             gr1.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
             gr1.DrawImage(Lbl1, LAB_SHOPNAME.Left - PIC_ZXing.Left, LAB_SHOPNAME.Top - PIC_ZXing.Top)
             gr1.DrawImage(pic_code, PIC_linecode.Left - PIC_ZXing.Left, PIC_linecode.Top - PIC_ZXing.Top)
    
             e.Graphics.DrawImage(PB1, NUM_XP.Value, NUM_YP.Value, NUM_W.Value, NUM_H.Value)
dotnet-visual-basic
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ahmedAlie-8738 ,
Could you please provide more information about PIC_ZXing, NUM_XP, NUM_YP, etc. in your code?
This can help us solve your problem better.

0 Votes 0 ·
ahmedAlie-8738 avatar image ahmedAlie-8738 JiachenLiMFST-9349 ·

hi JiachenLiMFST

First of all, thanks for the reply and follow up.

PIC_ZXing= The main picture box1 inside the picture box2 for the barcode and product label

NUM_XP, NUM_YP =NumericUpDown To change the width and height of picture box1.

and change the dimensions

0 Votes 0 ·

1 Answer

JiachenLiMFST-9349 avatar image
0 Votes"
JiachenLiMFST-9349 answered

Hi @ahmedAlie-8738 ,
Drawimage() will transform the image to the target according to some settings, but the algorithm is not controllable. For users, the dpi of the display is generally lower than that of the printer, and only the original image with a high dpi can be used to minimize the loss of scaling.
The code below is an example of printing a clear barcode.

         'Get the DPI of the printer
         Dim widthDPI = e.Graphics.DpiX
         Dim heightDPI = e.Graphics.DpiY
         Console.WriteLine(widthDPI)
         Console.WriteLine(heightDPI)
    
         Dim encodeOption = New EncodingOptions()
         ' This is to convert hundredths of an inch to pixels
         'For example, 200 actually means 2 inches, and 60 means 0.6 inches
         Dim bmpwidth = 400
         Dim bmpheight = 140
         'Convert the above inches to the pixels required by the picture. For example, if the DPI is 600, then one inch needs 600 pixels,
         ' So the formula is (hundredths of an inch / 100) * DPI = actual pixels
         encodeOption.Height = bmpheight * heightDPI / 100
         encodeOption.Width = bmpwidth * widthDPI / 100
    
         'Generate barcode image and save
         Dim wr As ZXing.BarcodeWriter = New BarcodeWriter()
         wr.Options = encodeOption
         wr.Format = BarcodeFormat.CODE_128
         Dim img = wr.Write("aabbcc")
         PIC_linecode.Image = img
    
         e.Graphics.DrawImage(img, new Rectangle(25, 25, bmpwidth, bmpheight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);

Why is the print image blurry?This is due to unit error.

The actual unit of image width and height is in pixels, but the width and height when printed are indeed in hundredths of an inch.

For example, if an image is 600px wide and 600px high, and the DPI of a printer is 600 in height and width, then when using DrawImage to print the image, it will interpret the 600-pixel width of the image as 600 percent of an inch ( 6 inches), the value has not changed, but the understanding of the unit is different,

So to print 6 inches wide, you need a span of 6*600DPI=3600 pixels, but the picture itself is only 600 pixels, so the width of the picture is enlarged to 3600 pixels, and the same is true for the height, which needs to be enlarged.

After zooming in, the bitmap will appear jagged. If it is a general printer, it can still print grayscale, and the picture can still be seen, but the blur is not very obvious. If it is a label printer, there is only one color of black, and those grayscale values ​​are to discard, resulting in very blurry printed labels.

Hope this could be helpful.
Best Regards.
Jiachen Li


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.