?
Solved

Print an Image in a picturebox control

Posted on 2005-03-22
5
Medium Priority
?
5,917 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

762 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