Results 1 to 5 of 5

Thread: Problems printing a jpg file

  1. #1
    jburke is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2010
    Posts
    4
    Reputation
    0

    Problems printing a jpg file

    Am having problems printing a stored jpg file. I can load it rotate it save it but when it comes to printing it i just get a small portion of the image. . Note opening the saved portion file "rotated.jpg" contains the entire image. Here is the code


    Imports System.Drawing.Printing
    Imports System.Drawing.Image

    Public Class Form1

    Private WithEvents DialogsPrintDocument As PrintDocument

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub DialogsPrintDocument_QueryPageSettings(ByVal sender As Object, ByVal e As _
    System.Drawing.Printing.QueryPageSettingsEventArgs ) _
    Handles DialogsPrintDocument.QueryPageSettings

    e.PageSettings.Landscape = True

    End Sub

    Private Sub DialogsPrintDocument_PrintPage(ByVal sender As Object, _
    ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles DialogsPrintDocument.PrintPage

    Dim img As Image

    img = Image.FromFile("C:\xxx.jpg")

    img.RotateFlip(RotateFlipType.Rotate180FlipNone)

    e.HasMorePages = False
    e.Graphics.DrawImage(img, New Point(0, 0))
    img.Save("C:\rotated.jpg")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    DialogsPrintDocument = New PrintDocument

    With PrintDialog1

    .AllowCurrentPage = False
    .AllowPrintToFile = False
    .AllowSelection = False
    .AllowSomePages = False
    .Document = DialogsPrintDocument
    .PrinterSettings.DefaultPageSettings.Margins.Top = 25
    .PrinterSettings.DefaultPageSettings.Margins.Botto m = 25
    .PrinterSettings.DefaultPageSettings.Margins.Left = 25
    .PrinterSettings.DefaultPageSettings.Margins.Right = 25
    End With

    If PrintDialog1.ShowDialog = DialogResult.OK Then

    DialogsPrintDocument.PrinterSettings = PrintDialog1.PrinterSettings
    strPrintRecord = TextBox1.Text

    DialogsPrintDocument.Print()

    End If
    End Sub
    End Class

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,562
    Reputation
    2737
    try .DrawImage(img, e.MarginBounds), adjust the rectangle if you need it scaled.
    Also remember; img.Dispose()

  3. #3
    jburke is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2010
    Posts
    4
    Reputation
    0
    Well that printed but this time its a full page. I am looking to print the actual size of the image. Thanks for the line
    img.dispose() forgot about that one.

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,562
    Reputation
    2737
    If the image is smaller than page specifying a Point as your first code is sufficient to draw the full image. If the image is larger than page you either have to draw it within a rectangle in the page (similar to that I suggested), or draw it over multiple pages. For multipage printout you have to work out those rectangles and use a DrawImage method where you both specify source and target rectangle, regarding PrintPage you also have to work with e.HasMorePages to control when another page needs to output.

  5. #5
    jburke is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2010
    Posts
    4
    Reputation
    0
    Yeah i would agree but all the images are about 5*8 they just won't print correctly!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking