22-09-17, 02:23 AM
الأسرع و الأفضل لك أ ن تستخدم الدوال التالية
PHP كود :
Public Shared Function ToBitmap(buffer() As Byte, width As Integer, height As Integer) As Drawing.Bitmap
Dim bmp As New System.Drawing.Bitmap(width, height)
Dim data As Imaging.BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), Imaging.ImageLockMode.WriteOnly, Imaging.PixelFormat.Format32bppArgb)
Runtime.InteropServices.Marshal.Copy(buffer, 0, data.Scan0, buffer.Length)
bmp.UnlockBits(data)
Return bmp
End Function
Public Shared Function ToBytes(bmp As Bitmap) As Byte()
Dim data As Imaging.BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppArgb)
Dim buffer As Byte() = New Byte(data.Stride * data.Height - 1) {}
Runtime.InteropServices.Marshal.Copy(data.Scan0, buffer, 0, buffer.Length)
bmp.UnlockBits(data)
Return buffer
End Function
Retired

