Skip to content

Print large Image (JPG) file to the printer

hai pham

Asked Dec 10, 2008, 7:14 PM EST1 answer
Share
LinkedInX

I am trying to write a program to print an image (jpg file) dirrectly to the default printer.  Here is the code.

Imports System.Drawing
Imports System.Drawing.Printing

Module Module1
    Sub Main()
        Dim printer As PrintDocument = New PrintDocument
        AddHandler printer.PrintPage, AddressOf PrintImage
        printer.Print()
    End Sub

    Private Sub PrintImage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
        Dim img As Image = Image.FromFile("C:\...\MyImage.jpg")
        e.Graphics.DrawImage(img, 0, 0)
    End Sub

End Module

 

However, when I have a big image, resolution is very high (4000 x 6000 pixels).  I would like to resize the image first before I print.   Is there a way to resize the image?  Could some one help me?  Thanks

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • +1
    try this:

    Function ThumbnailCallback() AS Boolean
    Return False
    End Function

    Dim objCallback AS System.Drawing.Image.GetThumbnailImageAbort = new System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)

    Private Sub PrintImage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
            Dim img As Image = Image.FromFile("C:\...\MyImage.jpg")
    img = img.GetThumbnailImage(imageWidth, imageHeight, objCallback, IntPtr.Zero) ' first two parameters are type integer; either pass literals for width and height or define these before function call
            e.Graphics.DrawImage(img, 0, 0)
        End Sub

    +1