Which is the best approach for reading the color of bitmap pixels inside a closed polygon?
The closed polygon is defined as a list of System.Drawing.Point in the bitmap dimensions. I am using C# and .NET Framework.
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I know c# does not provide this functionality by default. The easiest way perhaps is to create a second image with a white background, where you
FillPolygonthe polygon with black pixels. Then you scan the entire second image for black pixels, and read each black pixel from the original image at the same coordinate.This will of course be slow if the polygon is a small part of a large image, but you can easily determine the bounds in which the polygon falls and only create a map for that area.
Another way is scan a line from (-1, 0) to (width + 1, 0) and calculate the intersections with each polygon line, after an intersection the next pixels are inside the polygon, and after the next intersection the pixels are outside. Then scan (-1, 1) to (width + 1, 1) etc.
Keep in mind that a line intersecting with a point exactly matching a polygon point should take extra care.