• 15 years ago
    I have a problem with printing pictures...

    for printing a picture opened in picturebox everything is fine...

    but I nead to print picture from a file, and when I set printdocument like:

           e.Graphics.DrawImage(Image.FromFile("c:\picture1.jpg"), 'i nead to put here something?')

    please help!
  • 15 years ago
    my sample code is printig on a form buit its exactaly the same.

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
         'Use the path of your image
         Dim TestImage As Image = Image.FromFile("C:\blah\blah.jpg")
         'Center your image with the width and height of the printing surface (e.width, e.height) instead of "me"
         Dim TestPoint As New Point(CType((Me.Width / 2) - (TestImage.Width / 2), Integer), CType((Me.Height / 2) - (TestImage.Height / 2), Integer))

         'We arent changing the scale of the original image so lets use the faster DrawImageUnscaled
         e.Graphics.DrawImageUnscaled(TestImage, TestPoint)
      End Sub
  • 15 years ago


    I created similar code like yours,

    it resizes picture so it fits paper size


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

    Dim image2 As Image = Image.FromFile("c:\slika2.jpg")
               Dim R As Rectangle
               Dim Width, Height, Left, Top As Integer
               Width = image2.Width
               Height = image2.Height

               With PrintDocument1.DefaultPageSettings.PaperSize

                   If Width < .Width Then
                       Left = (.Width - Width) / 2
                       Left = 0
                       Dim W As Single = Width / .Width
                       Dim H As Single = Height / .Height
                       Width = Width / W
                       Height = Height / H

                   End If
                   If Height < .Height Then
                       Top = (.Height - Height) / 2
                       Top = 0
                   End If
               End With
               R = New Rectangle(Left, Top, Width, Height)

               e.Graphics.DrawImage(image2, R)
    end sub

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“XML is like violence - if it's not working for you, you're not using enough of it.”