# Pixel Color C#

• ### Question

• Hi, I have a scanned image which contains some multiple-choice questions. So, first of all how could I calculate the average color for most pixels inside a specific circle (I already know how to get the color of one individual pixel)

Second, how got I reach an const location, at first I thought of reaching pixels but what if my scanned image has 150dpi, and the same image was scanned with 300dpi?

Wednesday, December 19, 2018 9:02 PM

### All replies

• Averaging is easy, assuming you know the size and location of the circle.  At 300 dpi, a 1/4" circle will have a diameter of 75 pixels.  The easy thing would be just to add up the R, G, and B components of all pixels in the surrounding square, and divide by 75x75.  A square containing a filled in circle will be much darker than a square with an empty circle.  Just two nested for loops, for y = 0 to 74, for x = 0 to 74, and add 'em up.

You ought to be able to get the DPI from the image header.  If not, then you can get it from the image size.  An 8.5x11 scanned sheet at 300 DPI is 2550 x 3300.  At 150 DPI it is 1275 x 1650.

Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

Thursday, December 20, 2018 12:32 AM
• Sorry for bothering, but what do you mean by saying: "You ought to be able to get the DPI from the image header."mean  could your provide a line of code in C#, because I found both:

`Image.HorizontalResolution`
`Image.VerticalResolution`

Thursday, December 20, 2018 2:50 PM

The two you found are different.

Image.HorizontalResolution Property is used for get the horizontal resolution, in pixels per inch, of this Image.

Image.VerticalResolution Property is used to get the vertical resolution, in pixels per inch, of this Image.

Best Regards,

Wendy

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Friday, December 21, 2018 7:39 AM
• Yes, that's it.  In virtually every case, those two values are identical.  If they aren't, you'll have to pick the one you want to use.

Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

Saturday, December 22, 2018 12:44 AM