Example #1
0
        /// <summary>
        /// 计算图像直方图
        /// </summary>
        /// <param name="ChartWidth">图的宽度</param>
        /// <param name="ChartHeight">图的高度</param>
        private void GetHistogram(int ChartWidth, int ChartHeight)
        {
            int[]  red         = new int[256];
            int[]  green       = new int[256];
            int[]  blue        = new int[256];
            double WidthOffset = (double)ChartWidth / 256;
            string reds        = "M 0," + ChartHeight + " ";
            string greens      = "M 0," + ChartHeight + " ";
            string blues       = "M 0," + ChartHeight + " ";

            core.PicProcess picProcess = new core.PicProcess();
            int             max        = picProcess.GetPixelCount(pic, red, green, blue);

            for (int i = 0; i < 256; i++)
            {
                int y = ChartHeight - ChartHeight * red[i] / max;
                reds   += (i * WidthOffset).ToString() + "," + y.ToString() + " ";
                y       = ChartHeight - ChartHeight * green[i] / max;
                greens += (i * WidthOffset).ToString() + "," + y.ToString() + " ";
                y       = ChartHeight - ChartHeight * blue[i] / max;
                blues  += (i * WidthOffset).ToString() + "," + y.ToString() + " ";
            }
            reds   += ChartWidth + "," + ChartHeight + " Z";
            greens += ChartWidth + "," + ChartHeight + " Z";
            blues  += ChartWidth + "," + ChartHeight + " Z";
            var converter = TypeDescriptor.GetConverter(typeof(System.Windows.Media.Geometry));

            RedPath   = (System.Windows.Media.Geometry)converter.ConvertFrom(reds);
            GreenPath = (System.Windows.Media.Geometry)converter.ConvertFrom(greens);
            BluePath  = (System.Windows.Media.Geometry)converter.ConvertFrom(blues);
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("RedPath"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("GreenPath"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BluePath"));
        }
Example #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     ChartPath.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, (Action)(() =>
     {
         core.PicProcess picProcess = new core.PicProcess();
         picProcess.GetPixelCount(bs, data[1], data[2], data[3]);
         for (int i = 0; i < 256; i++)
         {
             data[0][i] = data[1][i] + data[2][i] + data[3][i];
             max[0] = data[0][i] > max[0] ? data[0][i] : max[0];
             max[1] = data[1][i] > max[1] ? data[1][i] : max[1];
             max[2] = data[2][i] > max[2] ? data[2][i] : max[2];
             max[3] = data[3][i] > max[3] ? data[3][i] : max[3];
         }
         Channel.SelectedIndex = 0;
     }));
 }