ColorSampler.cs (1325B)
1 using Windows.Graphics.Imaging; 2 using Windows.UI; 3 using Windows.UI.Xaml.Media.Imaging; 4 5 namespace File360 6 { 7 class ColorSampler 8 { 9 public Color GetPixel(WriteableBitmap wb) 10 { 11 int pixel; //ARGB variable with 32 int bytes where 12 //sets of 8 bytes are: Alpha, Red, Green, Blue 13 byte r = 0; 14 byte g = 0; 15 byte b = 0; 16 int i = 0; 17 int j = 0; 18 //Skip every alternate pixel making the program 4 times faster 19 for (i = 0; i < wb.PixelWidth; i = i + 2) 20 { 21 for (j = 0; j < wb.PixelHeight; j = j + 2) 22 { 23 pixel = WriteableBitmapExtensions.GetPixeli(wb,i,j); //the ARGB integer(pixel) has the colors of pixel (i,j) 24 r = (byte)(r + (255 & (pixel >> 16))); //add up reds 25 g = (byte)(g + (255 & (pixel >> 8))); //add up greens 26 b = (byte)(b + (255 & (pixel))); //add up blues 27 } 28 } 29 r = (byte)(r / (wb.PixelWidth/2 * wb.PixelHeight/2)); 30 g = (byte)(g / (wb.PixelWidth / 2 * wb.PixelHeight / 2)); 31 b = (byte)(b / (wb.PixelWidth / 2 * wb.PixelHeight / 2)); 32 return Color.FromArgb(100, r, g, b); 33 } 34 } 35 36 }