1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Dim Image1Bitmap As Bitmap = TryCast(Image1, Bitmap)
Dim Image2Bitmap As Bitmap = TryCast(Image2, Bitmap)
Dim Image3Bitmap As New Bitmap(Image1Bitmap.Width, Image1Bitmap.Height, Image1Bitmap.PixelFormat)
If Image1Bitmap Is Nothing OrElse Image2Bitmap Is Nothing Then
Return True
End If
Dim bytes As Integer = Image1.Width * Image1.Height * (Image.GetPixelFormatSize(Image1.PixelFormat) / 8)
Dim result As Boolean = True
Dim b1bytes As Byte() = New Byte(bytes - 1) {}
Dim b2bytes As Byte() = New Byte(bytes - 1) {}
Dim b3bytes As Byte() = New Byte(bytes - 1) {}
Dim bmd1 As BitmapData = Image1Bitmap.LockBits(New Rectangle(0, 0, Image1Bitmap.Width - 1, Image1Bitmap.Height - 1), ImageLockMode.[ReadOnly], Image1Bitmap.PixelFormat)
Dim bmd2 As BitmapData = Image2Bitmap.LockBits(New Rectangle(0, 0, Image2Bitmap.Width - 1, Image2Bitmap.Height - 1), ImageLockMode.[ReadOnly], Image2Bitmap.PixelFormat)
Dim bmd3 As BitmapData = Image3Bitmap.LockBits(New Rectangle(0, 0, Image3Bitmap.Width - 1, Image3Bitmap.Height - 1), ImageLockMode.[ReadWrite], Image3Bitmap.PixelFormat)
Marshal.Copy(bmd1.Scan0, b1bytes, 0, bytes)
Marshal.Copy(bmd2.Scan0, b2bytes, 0, bytes)
Marshal.Copy(bmd3.Scan0, b3bytes, 0, bytes)
' Image 3 blanche
For counter As Integer = 0 To b3bytes.Length - 1 Step 1
b3bytes(counter) = 255
Next
'boucle sur chaque pixel
For n As Integer = 0 To b1bytes.Length - 1 Step 3
Dim Rvalue As Double = b1bytes(n) / b2bytes(n)
Dim Gvalue As Double = b1bytes(n + 1) / b2bytes(n + 1)
Dim Bvalue As Double = b1bytes(n + 2) / b2bytes(n + 2)
'si valeur hors seuil on passe en rouge
If (Rvalue + Gvalue + Bvalue) / 3 < 1 - NumericUpDown1.Value / 100 Or (Rvalue + Gvalue + Bvalue) / 3 > 1 + NumericUpDown1.Value / 100 Then
'set pixel rouge
b3bytes(n) = 0
b3bytes(n + 1) = 0
b3bytes(n + 2) = 255
result = False
End If
Next
Marshal.Copy(b3bytes, 0, bmd3.Scan0, bytes)
Image1Bitmap.UnlockBits(bmd1)
Image2Bitmap.UnlockBits(bmd2)
Image3Bitmap.UnlockBits(bmd3)
PictureBox1.Image = Image3Bitmap |
Partager