Results 1 to 5 of 5

Thread: GDI+ PictureBox - DPI Blurry Output

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    GDI+ PictureBox - DPI Blurry Output

    Hello,

    I am developing a Ticket Printing application in VB.NET
    The issue I am having is that my "ticket artwork" is pixel perfect, but when outputting to PDF... the quality is bad.

    Here is my apps program flow...

    - Load (dialog box) a ticket image (created at 280w x 123h pixels) into PictureBox (i.e. imgScrn)
    - The actual image looks great before bringing into app (#3 on screenshot below)
    - Then using the Paint event of the picture box, I paint the 2 Ticket Numbers on top using e.graphics (GDI+)
    - I do use "g1.SmoothingMode = SmoothingMode.AntiAlias" for the Numbers.
    - The actual ticket image doesn't look bad on the screen (#1 on screenshot below)

    However, look at the PDF output.... everything looks bad. (#2 on screenshot below)
    I am thinking that the images and numbers outputted on the PDF are actually larger then the original... thus jaggies.

    Code-wise....
    - I am using Pts for for text and measurements.
    - My PDF page size is 612x792... this gives me a letter sized page

    I am not sure if I have my DPI set properly or at all.

    Code:
     Private Sub mnuPrint_Click(sender As Object, e As EventArgs) Handles mnuPrint.Click
    
            'set general variables
            Dim iLF As Integer = 26  'left margin
            Dim iTP As Integer = 27  'top margin
            Dim iCTR As Integer = 306  'top margin
            Dim imgW As Integer = 280  'img width
            Dim imgH As Integer = 123  'img height
            Dim cutL As Integer = 15  'cutline left
            Dim cutR As Integer = 597  'cutline right
    
            'Create a New instance of PdfDocument.
            Dim pdfDoc = New Syncfusion.Pdf.PdfDocument()
    
            'Change page size
            pdfDoc.PageSettings = New Syncfusion.Pdf.PdfPageSettings(New SizeF(612, 792))
    
            'Add a New page to the document
            Dim pdfPageX = pdfDoc.Pages.Add()
            Dim pdfGraphicsX = pdfPageX.Graphics
    
            'add page border
            Dim cutBorder = New RectangleF(iLF, iTP, 560, 738)
            Dim pdfPen = New PdfPen(PdfBrushes.Silver, 1.0F)
            Dim pdfBrushX = PdfBrushes.White
    
            'Draw rectangle using PdfPen And PdfBrush.
            pdfGraphicsX.DrawRectangle(pdfPen, pdfBrushX, cutBorder)
    
            'draw center line
            pdfGraphicsX.DrawLine(PdfPens.Silver, iCTR, 15, iCTR, 775)
    
            'horz lines
            pdfGraphicsX.DrawLine(PdfPens.Silver, cutL, imgH + iTP, cutR, imgH + iTP)
            pdfGraphicsX.DrawLine(PdfPens.Silver, cutL, (imgH * 2) + iTP, cutR, (imgH * 2) + iTP)
            pdfGraphicsX.DrawLine(PdfPens.Silver, cutL, (imgH * 3) + iTP, cutR, (imgH * 3) + iTP)
            pdfGraphicsX.DrawLine(PdfPens.Silver, cutL, (imgH * 4) + iTP, cutR, (imgH * 4) + iTP)
            pdfGraphicsX.DrawLine(PdfPens.Silver, cutL, (imgH * 5) + iTP, cutR, (imgH * 5) + iTP)
    
            Dim bm As Bitmap = New Bitmap(imgScrn.ClientSize.Width, imgScrn.ClientSize.Height)
            imgScrn.DrawToBitmap(bm, imgScrn.ClientRectangle)
            Dim pdfImageX = PdfImage.FromImage(bm)
    
            ' PLACE IMAGES on CANVAS
            pdfGraphicsX.DrawImage(pdfImageX, iLF, iTP, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF + imgW, iTP, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF, iTP + imgH, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF + imgW, iTP + imgH, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF, iTP + imgH * 2, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF + imgW, iTP + imgH * 2, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF, iTP + imgH * 3, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF + imgW, iTP + imgH * 3, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF, iTP + imgH * 4, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF + imgW, iTP + imgH * 4, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF, iTP + imgH * 5, imgW, imgH)
            pdfGraphicsX.DrawImage(pdfImageX, iLF + imgW, iTP + imgH * 5, imgW, imgH)
    
            'Save And close the document.
            pdfDoc.Save("pdfoutput.pdf")
            pdfDoc.Close(True)
    
            'open file
            System.Diagnostics.Process.Start("pdfoutput.pdf")
    
        End Sub
    Name:  tickprint01.jpg
Views: 417
Size:  35.9 KB

    Other than the "jaggies" this basic beginnings of this app is working.
    Any insight on how I can improve this would be appreciated.

    Thanks
    Last edited by technipixel; Dec 22nd, 2017 at 10:49 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    Re: GDI+ PictureBox - DPI Blurry Output

    FYI.... my app is returning a DPI of 96.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    Re: GDI+ PictureBox - DPI Blurry Output

    I have defiantly figured out that the image is being stretched.
    I was setting the w & h when drawing.
    If I just leave off the width & height, the image is just placed at x-y position.

    However...

    My image is in pixels and the page values are in points.
    How do i get both of them the same so I can code more accurately?

    So, for example... the PicBox values reflect the actual image size.
    But, it translates different when coded using a points measuring system.

    Learning a lot!

    More insight would be appreciated.

  4. #4
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: GDI+ PictureBox - DPI Blurry Output

    I can't help with the PDF stuff but bear in mind that if you capture your image at 280 x 123 pixels and try to print it more than about an inch wide it is going to look pretty awful. You can't magically increase the DPI of a bitmap image; it is what it is.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Location
    Sabattus, ME
    Posts
    87

    Re: GDI+ PictureBox - DPI Blurry Output

    Okay... by properly getting the correct image dimensions for the output, it does fix the "jaggies" (pretty close at least)

    However, just for my learning and to better code....

    How can also always make sure that my DPI for images and output is always the same.

    I understand what DPI and Screen Resolution is...

    But, what do I need to do to consider each person's individual PC.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width