//创建直方图 private void DrawHistogram(CanvasDrawingSession drawingSession, Size size, EffectChannelSelect channelSelect, CanvasLinearGradientBrush brush) { int binCount = (int)CanvasControl.ActualWidth; //256;//矩形数量 const float graphPower = 0.25f; // 非线性规模使得图更清楚地显示微小的变化。 try { float[] histogram = CanvasImage.ComputeHistogram(App.Model.MainRenderTarget, App.Model.MainRenderTarget.Bounds, drawingSession, channelSelect, binCount); var w = (float)size.Width / binCount; var h = (float)size.Height; for (int i = 0; i < binCount; i++) { var x = i * w; var y = (1 - (float)Math.Pow(histogram[i], graphPower)) * h; brush.StartPoint = new Vector2(x, y); brush.EndPoint = new Vector2(x, h); drawingSession.FillRectangle(x, y, w, h - y, brush); } } catch (Exception) { } }
void DrawHistogram(CanvasDrawingSession drawingSession, Size size, EffectChannelSelect channelSelect, CanvasLinearGradientBrush brush) { const int binCount = 64; const float graphPower = 0.25f; // Nonlinear scale makes the graph show small changes more clearly. float[] histogram = CanvasImage.ComputeHistogram(hueEffect, bitmap.Bounds, drawingSession, channelSelect, binCount); var w = (float)size.Width / binCount; var h = (float)size.Height; for (int i = 0; i < binCount; i++) { var x = i * w; var y = (1 - (float)Math.Pow(histogram[i], graphPower)) * h; brush.StartPoint = new Vector2(x, y); brush.EndPoint = new Vector2(x, h); drawingSession.FillRectangle(x, y, w, h - y, brush); } }
static void TestHistogram(CanvasBitmap bitmap, Rect sourceRectangle, EffectChannelSelect channelSelect, params float[] expected) { var histogram = CanvasImage.ComputeHistogram(bitmap, sourceRectangle, bitmap.Device, channelSelect, 2); CollectionAssert.AreEqual(expected, histogram); }