3 Replies - 3030 Views - Last Post: 25 August 2013 - 01:59 PM Rate Topic: -----

#1 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Resize image (picturebox) for printing

Posted 25 August 2013 - 01:11 PM

Hi,
I want to print a picture from picturebox, but when picture is too big then size doesn't fit on the paper, so I have to somehow resize the image to fit the paper... any ideas?


My print code:

Print Button pressed

If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then


            Call Watermark()

            PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings

            PrintDocument1.Print()

        End If


PrintDocument1:

   Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim graphics As Graphics = e.Graphics

        graphics.DrawImage(PictureBox1.Image, New Point(100, 100))

    End Sub


Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Resize image (picturebox) for printing

#2 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: Resize image (picturebox) for printing

Posted 25 August 2013 - 01:38 PM

I figured out a solution, Thank you!

#Close
Was This Post Helpful? 0
  • +
  • -

#3 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 966
  • Joined: 09-May 09

Re: Resize image (picturebox) for printing

Posted 25 August 2013 - 01:53 PM

View PostNeph1x, on 25 August 2013 - 02:38 PM, said:

I figured out a solution, Thank you!

#Close


Hi, im glad the issue has been resolved however you didn't post your solution

these forums are not only to aid the creator of the topic but those who may come across this issue in the near future :)
Was This Post Helpful? 0
  • +
  • -

#4 Neph1x  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 110
  • Joined: 19-November 11

Re: Resize image (picturebox) for printing

Posted 25 August 2013 - 01:59 PM

Yes, of course my bad sorry!

Add:
Print Document
Print Dialog


Print Document Code:

 Dim ImgX As Integer
        Dim ImgY As Integer
        Dim PSizeX As Integer
        Dim PSizeY As Integer
        Dim ScaleX As Double
        Dim ScaleY As Double
        Dim RecX As Integer
        Dim RecY As Integer
        Dim ScaleM As Double


        ImgX = Me.PictureBox1.Image.Height
        ImgY = Me.PictureBox1.Image.Width
        If Me.PrintDocument1.DefaultPageSettings.Landscape = False Then
            PSizeX = Me.PrintDocument1.DefaultPageSettings.PaperSize.Height
            PSizeY = Me.PrintDocument1.DefaultPageSettings.PaperSize.Width
        Else
            PSizeX = Me.PrintDocument1.DefaultPageSettings.PaperSize.Width
            PSizeY = Me.PrintDocument1.DefaultPageSettings.PaperSize.Height
        End If
        ScaleX = PSizeX / ImgX
        ScaleY = PSizeY / ImgY
        If ScaleX < ScaleY Then
            ScaleM = ScaleX
        Else : ScaleM = ScaleY
        End If
        RecY = ImgY * ScaleM
        RecX = ImgX * ScaleM
        e.Graphics.DrawImage(PictureBox1.Image, 0, 0, RecY, RecX)


Print Dialog Code:

 If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then



            PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings

            PrintDocument1.Print()

        End If

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1