Public Shared Function Render(ByRef pdfDoc As PDFLibNet.PDFWrapper) As System.Drawing.Bitmap
Try
If pdfDoc IsNot Nothing Then
Dim PW As Integer = pdfDoc.PageWidth
Dim PH As Integer = pdfDoc.PageHeight
Dim backbuffer As System.Drawing.Bitmap = New Bitmap(PW, PH)
pdfDoc.ClientBounds = New Rectangle(0, 0, pdfDoc.PageWidth, pdfDoc.PageHeight)
Dim g As Graphics = Graphics.FromImage(backbuffer)
Using g
Dim hdc As IntPtr = g.GetHdc()
pdfDoc.DrawPageHDC(hdc)
g.ReleaseHdc()
End Using
g.Dispose()
Return backbuffer
End If
Catch ex As Exception
Throw ex
Return Nothing
End Try
Return Nothing
End Function
This function is drawing the image into the hdc of variable "backbuffer" of type bitmap, that return from function. But I dissatisfied by two big increases of memory (my image is big) in this function:
at line
Dim backbuffer As System.Drawing.Bitmap = New Bitmap(PW, PH)
and at line
Dim hdc As IntPtr = g.GetHdc()
So, I have a questions:
why second line increases a memory for the size that equivalent size of my image
and why if I draw into the hdc, I get the drawn bitmap, that I return (maybe first there is boxing, and second there is unboxing) ?
And if I draw into the hdc (optimized copy of my image for the concrete drawing surface), how my drawing became back to the original "backbuffer" Bitmap from that optimized copy?