public double?getWhiteBalance(Dictionary <TimeSpan, WriteableBitmap> sl) { double y = 0, pb = 0, pr = 0; if (sl.Count == 0) { return(null); } foreach (WriteableBitmap b in sl.Values) { var p = b.PixelBuffer.ToArray(); for (int i = 0; i < p.Length; i += 4) { LColor lc = new LColor(Color.FromArgb(255, p[i + 2], p[i + 1], p[i])); lc.CalculateRGB2YPbPr(); y += lc.YPbPr_Y; pb += lc.YPbPr_Pb; pr += lc.YPbPr_Pr; } } return(y / Math.Max(pb, pr)); }