Looking for some much appreciated help. I'm trying to draw a smaller bitmap into a larger bitmap. I'm trying to use Lockbits to make the process go faster. But my .DrawImage function will not execute. The error is a general GDI+ error (Unhandled Exception). This is my code snippet. What am i doing wrong? The Misc.Lockbitmap is verified to work so i don't think the error is there, but I can put that code up here as well if that helps.
I should add that this is part of a much bigger code. To clarify: I am able to use execute the line with .DrawImage if i disable the lockbits.
Dim largerFile As New Bitmap(BitMapSizeX, BitMapSizeY)
Call MiscClass.LockBitmap(largerFile, PixBytes, RowSizeBytes)
Dim GraphicsModifier As Graphics = Graphics.FromImage(largerFile)
Dim currentPic As New Bitmap(smallerFilePath.Tostring) ' & ".jpg")
GraphicsModifier.DrawImage(currentPic, picAndLoc.XLoc, picAndLoc.YLoc, ComponentSize, ComponentSize)
Public Shared m_BitmapData As BitmapData
' Lock the bitmap's data.
Public Shared Sub LockBitmap(ByRef bm As Bitmap, ByRef PixBytes() As Byte, ByRef RowSizeBytes As Integer)
Dim bounds As Rectangle = New Rectangle(0, 0, bm.Width, bm.Height)
m_BitmapData = bm.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format24bppRgb)
RowSizeBytes = m_BitmapData.Stride
' Allocate room for the data.
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
ReDim PixBytes(total_size)
Marshal.Copy(m_BitmapData.Scan0, PixBytes, 0, total_size)
End Sub