24-04-17, 04:36 PM
(آخر تعديل لهذه المشاركة : 24-04-17, 04:54 PM {2} بواسطة silverlight.)
هذا اسرع كود علي الاطلاق لتحويل الصورة الي مصفوفة Byte
وهذا الكود لمقارنة المصفوفتان
الكود التالي يوضح كيفية استخدام الدالتان معا لمقارنة الصورتان
PHP كود :
Friend Function BitmapToBytes(bitmap As Drawing.Bitmap) As Byte()
Dim data As System.Drawing.Imaging.BitmapData = bitmap.LockBits(New System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim buffer As Byte() = New Byte(data.Stride * data.Height - 1) {}
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, buffer, 0, buffer.Length)
bitmap.UnlockBits(data)
Return buffer
End Function
وهذا الكود لمقارنة المصفوفتان
PHP كود :
Friend Function IsEqual(a() As Byte, b() As Byte) As Boolean
Dim length As Integer = a.Length Xor b.Length
Dim i As Integer = 0
While i < a.Length AndAlso i < b.Length
length = length Or a(i) Xor b(i)
i += 1
End While
Return length = 0
End Function
PHP كود :
Dim bmp1 As Bitmap = CType(My.Resources.ResourceManager.GetObject("اسم الصورة"), Bitmap)
Dim buffer1 As Byte() = BitmapToBytes(bmp1)
Dim bmp2 As Bitmap = picturebox1.image
Dim buffer2 As Byte() = BitmapToBytes(bmp2)
IF IsEqual(buffer1, buffer2) Then
' do somethign if both images are equals
Else
' do somethign if both images are not equals
End IF

