VB.NET: Print Multiple Images on Multiple Pages

Here is a sample of the printing routine:

Public Shared Sub PrintMultiFunc(ByVal sender As Object, ByVal e As PrintPageEventArgs)

Dim dibLoad As System.UInt32
Dim dibPage As System.UInt32
Dim Pages As Integer
Dim i32dibpage As Int32

dibLoad = FreeImageAPI.FreeImage.Ope
nMultiBitmap(FreeImageAPI.FIF.FIF_TIFF, "C:\abc.tif", False, False, True)
Pages = FreeImageAPI.FreeImage.GetPageCount(dibLoad)

For counter As Integer = 0 To (Pages - 1)

Dim MyFont As New Font("Arial", 30)
Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim lineheight As Single = MyFont.GetHeight(e.Graphics)
Dim cFIBImage = dibPage

'routine to convert UInt32 to system.drawing.bitmap
Dim pBmpBitmap As Bitmap = New Bitmap(Convert.ToInt32(FreeImageAPI.FreeImage.GetWidth(cFIBImage)), Convert.ToInt32(FreeImageAPI.FreeImage.GetHeight(cFIBImage)))
Dim pGraGraphics As Graphics = Graphics.FromImage(pBmpBitmap)
Dim pIPrHDC As IntPtr = pGraGraphics.GetHdc
Dim pIPrBits As IntPtr = FreeImageAPI.FreeImage.GetBits(cFIBImage)
Dim pIPrInfo As IntPtr = FreeImage_GetInfo(cFIBImage)
Call SetDIBitsToDevice(pIPrHDC.ToInt32, 0, 0, pBmpBitmap.Width, pBmpBitmap.Height, 0, 0, 0, pBmpBitmap.Height, pIPrBits, pIPrInfo, DIB_RGB_COLORS)
Call pGraGraphics.ReleaseHdc(pIPrHDC)


'define parameters of bitmap and rescale to fit margins.
Dim image = pBmpBitmap
Dim width As Integer = image.Width
Dim height As Integer = image.Height
Dim destinationRect As New RectangleF(
10, _
10, _
0.32F * width, _
0.32F * height)
Dim sourceRect As New RectangleF(0, 0, 1.0F * width, 1.0F * height)

'Send to printer
e.Graphics.DrawImage( _
image, _
destinationRect, _
sourceRect, _
GraphicsUnit.Pixel)
e.HasMorePages = True

'release locked image
FreeImageAPI.FreeImage.UnlockPage(dibLoad, counter, False)
Next
e.HasMorePages = False
End Sub

Comments