I am trying to print an image in vb.net. The size of the image is dynamic, and is derived from a panel, so can span more than 1 page. For this, I am cropping the image and printing the first part, then recursively calling the procedure to print the next section. The first page prints okay, but the subsequent pages are blank, as is the image that is supposed to be on them.
800 is height of page, 1100 is width. All the save images are to pinpoint the problem: restimg.bmp comes up as blank, so the problem seems to be in the second using statement. I know very little about image manipulation, so simple terms and example please.
This is the code.
Sub recersive_print(ByVal WholeImg As Bitmap)
If WholeImg.Height > 800 Then
Dim CropRect As New Rectangle(0, 0, 1100, 800)
Dim CropImage = New Bitmap(CropRect.Width, CropRect.Height)
Dim restofimg = New Bitmap(1100, WholeImg.Height - 800)
Dim restofingrect As New Rectangle(0, 0, restofimg.Height, restofimg.Width)
Using grp = Graphics.FromImage(CropImage)
grp.DrawImage(WholeImg, New Rectangle(0, 0, CropRect.Width, CropRect.Height), CropRect, GraphicsUnit.Pixel)
End Using
CropImage.Save("E:\cropped.bmp")
Using grp = Graphics.FromImage(restofimg)
grp.DrawImage(WholeImg, New Rectangle(0, CropRect.Height, restofimg.Width, restofimg.Height), restofingrect, GraphicsUnit.Pixel)
End Using
'img_filepath = Application.StartupPath & "\out" & Val(img_filepath) + 1 & ".bmp"
img_to_print = CropImage
'CropImage.Save(img_filepath)
PrintDocument1.Print()
'WholeImg.Dispose()
restofimg.Save("E:\Rest.bmp")
recersive_print(restofimg)
Else
img_to_print = WholeImg
img_to_print.Save("E:\out.bmp")
PrintDocument1.Print()
End If
End Sub
Thanks
EDIT: img_to_print is used in the following way
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim g As Graphics = e.Graphics
g.DrawImage(img_to_print, 5, 5)
End Sub