?
Solved

Print an Image in a picturebox control

Posted on 2005-03-22
5
Medium Priority
?
6,226 Views
Last Modified: 2012-05-05
hi,

Below code prints image on a vb.net picturebox control. if there is a large image it fits it exactly inside the picturebox control. But the print lies during printing instead of printing the image size on the picturebox control it prints actual image size.

How could we print the image as per the size of picturebox?

here is the code used:
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pd As New System.Drawing.Printing.PrintDocument
        AddHandler pd.PrintPage, AddressOf OnPrintPage
        pd.Print()
    End Sub
    Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        e.Graphics.DrawImage(PictureBox1.Image, 0, 0)
    End Sub
0
Comment
Question by:sainavya1215
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 13599873
       Dim inp As IntPtr = New IntPtr
        Dim result As System.Drawing.Image
        result = PictureBox1.Image.GetThumbnailImage(PictureBox1.Width, PictureBox1.Height, Nothing, inp)

Then you can use "result" instead "PictureBox1.Image"
0
 

Author Comment

by:sainavya1215
ID: 13604703
Could u pls let me know what code has to be eliminated here  and where exactly is ur code to be added.......

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pd As New System.Drawing.Printing.PrintDocument
        AddHandler pd.PrintPage, AddressOf OnPrintPage
        pd.Print()
    End Sub
    Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        e.Graphics.DrawImage(PictureBox1.Image, 0, 0)
    End Sub
0
 
LVL 6

Accepted Solution

by:
Svetlin_Panayotov earned 1400 total points
ID: 13605546
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pd As New System.Drawing.Printing.PrintDocument
        AddHandler pd.PrintPage, AddressOf OnPrintPage
        pd.Print()
    End Sub

    Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim inp As IntPtr = New IntPtr
        Dim result As System.Drawing.Image
        result = PictureBox1.Image.GetThumbnailImage(PictureBox1.Width, PictureBox1.Height,             Nothing, inp)
        e.Graphics.DrawImage(result, 0, 0)
    End Sub
0
 

Author Comment

by:sainavya1215
ID: 13615118
Thanks for that........
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 13618974
you're welcome :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question