file360

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 
using Windows.Graphics.Imaging;
using Windows.UI;
using Windows.UI.Xaml.Media.Imaging;

namespace File360
{
    class ColorSampler
    {
        public Color GetPixel(WriteableBitmap wb)
        {
            int pixel; //ARGB variable with 32 int bytes where
                       //sets of 8 bytes are: Alpha, Red, Green, Blue
            byte r = 0;
            byte g = 0;
            byte b = 0;
            int i = 0;
            int j = 0;
            //Skip every alternate pixel making the program 4 times faster
            for (i = 0; i < wb.PixelWidth; i = i + 2)
            {
                for (j = 0; j < wb.PixelHeight; j = j + 2)
                {
                    pixel = WriteableBitmapExtensions.GetPixeli(wb,i,j); //the ARGB integer(pixel) has the colors of pixel (i,j)
                    r = (byte)(r + (255 & (pixel >> 16))); //add up reds
                    g = (byte)(g + (255 & (pixel >> 8))); //add up greens
                    b = (byte)(b + (255 & (pixel))); //add up blues
                }
            }
            r = (byte)(r / (wb.PixelWidth/2 * wb.PixelHeight/2));
            g = (byte)(g / (wb.PixelWidth / 2 * wb.PixelHeight / 2));
            b = (byte)(b / (wb.PixelWidth / 2 * wb.PixelHeight / 2));
            return Color.FromArgb(100, r, g, b);
        }
    }
    
}