21-01-16, 10:32 AM
سلام
الرجاء تحويل البرنامج من c# الي vb.net
البرنامج عبارة تحويل صور الي ابيض واسود
جربت تحويله عن طريق الموقع http://converter.telerik.com/
ولكن بعد التحويل يعطي خطا البرنامج
Public Function ConvertImage(im As Image) As Image
Dim gx As Integer(,) = New Integer(,) {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}
' The matrix Gx
Dim gy As Integer(,) = New Integer(,) {{1, 2, 1}, {0, 0, 0}, {-1, -2, -1}}
' The matrix Gy
Dim b As Bitmap = DirectCast(im, Bitmap)
Dim b1 As New Bitmap(im)
For i As Integer = 1 To b.Height - 2
' loop for the image pixels height
For j As Integer = 1 To b.Width - 2
' loop for image pixels width
Dim new_x As Single = 0, new_y As Single = 0
Dim c As Single
For hw As Integer = -1 To 1
'loop for cov matrix
For wi As Integer = -1 To 1
Dim bColor As Color = b.GetPixel(j + wi, i + hw)
Dim rColor As Color = b.GetPixel(j + wi, i + hw)
Dim gColor As Color = b.GetPixel(j + wi, i + hw)
c = CSng(Math.Min(bColor.B, 255) + Math.Min(rColor.R, 255) + Math.Min(gColor.G, 255)) / 3
new_x += gx(hw + 1, wi + 1) * (c)
new_y += gy(hw + 1, wi + 1) * (c)
Next
Next
If new_x * new_x + new_y * new_y > 128 * 128 Then
b1.SetPixel(j, i, Color.Black)
Else
b1.SetPixel(j, i, Color.White)
End If
Next
Next
Return DirectCast(b1, Image)
End Function
