Re: Color shades rgb help
Hi Tweaker, Here's a typical way to check if two colors match within a certain tolerance. I think that's what you are after.
You check if the Red, Green and Blue components are each within tolerance limits. For example:
Code:
Dim tolerance as Integer = 8
Dim testColor as Color = Color.Black
'then put this in the middle of the loop instead of just If bmp.GetPixel(x, y) = ...
Dim clr As Color = bmp.GetPixel(x, y)
If Math.Abs(clr.R - testColor.R) < tolerance AndAlso _
Math.Abs(clr.G - testColor.G) < tolerance AndAlso _
Math.Abs(clr.B - testColor.B) < tolerance Then _
newImage.SetPixel(x, y, Color.White)
End If
You can obviously try this out with different colors and tolerances.
As minitech pointed out in the other thread, using GetPixel and SetPixel isn't the most efficient way to do pixel processing. But I think it's a good idea to get it working this way first, and leave speeding it up to later if it turns out to be necessary. (By the way, you should put PictureBox2.BackgroundImage = ... outside the loop, because otherwise you will be doing it thousands of times when you really only need to do it once.)
BB
Re: Color shades rgb help
Quote:
Originally Posted by
boops boops
Hi Tweaker, Here's a typical way to check if two colors match within a certain tolerance. I think that's what you are after.
You check if the Red, Green and Blue components are each within tolerance limits. For example:
Code:
Dim tolerance as Integer = 8
Dim testColor as Color = Color.Black
'then put this in the middle of the loop instead of just If bmp.GetPixel(x, y) = ...
Dim clr As Color = bmp.GetPixel(x, y)
If Math.Abs(clr.R - testColor.R) < tolerance AndAlso _
Math.Abs(clr.G - testColor.G) < tolerance AndAlso _
Math.Abs(clr.B - testColor.B) < tolerance Then _
newImage.SetPixel(x, y, Color.White)
End If
You can obviously try this out with different colors and tolerances.
As minitech pointed out in the other thread, using GetPixel and SetPixel isn't the most efficient way to do pixel processing. But I think it's a good idea to get it working this way first, and leave speeding it up to later if it turns out to be necessary. (By the way, you should put
PictureBox2.BackgroundImage = ... outside the loop, because otherwise you will be doing it thousands of times when you really only need to do it once.)
BB
wow man this was 100% exactly what i was looking for :thumb:
Your amazing also pro :D Thanks So Much