编辑图像时出现AccessViolationException

时间:2014-04-18 10:54:00

标签: vb.net image memory image-processing

这是我使用的代码(b是位图):

 Private Class BitmapData
        Public Bitmap As Bitmap
        Public ByteData As Byte()
        Public BitmapData As Imaging.BitmapData

        Public Shared Function LockBits(ByVal b As Bitmap) As BitmapData

            LockBits = New BitmapData
            LockBits.Bitmap = b
            Dim bmpRect As New Rectangle(0, 0, b.Width, b.Height)
            ReDim LockBits.ByteData(b.Width * b.Height * 4 - 1)

            LockBits.BitmapData = b.LockBits(bmpRect, Imaging.ImageLockMode.ReadWrite, b.PixelFormat)
            System.Runtime.InteropServices.Marshal.Copy(LockBits.BitmapData.Scan0, LockBits.ByteData, 0, LockBits.ByteData.Length)
        End Function
End class

当我运行代码时,会出现AccessViolationException。

代码有什么问题,以及如何修复它?

0 个答案:

没有答案