Пример #1
0
        //用于向列表中添加一个操作并将 _redoItem 设为空
        //当确实向列表中添加了一个操作时返回 true
        //否则,如果要添加项为空或者要添加项与列表中最后一项的操作类型相同则返回 false
        //这样,拖拉同一个滑块时将只会向列表中添加一个操作
        public bool Add(ActionItem actionItem)
        {
            //添加一个新操作时先置空 redo
            _redoItem = null;
            ActionItem item = this.LastItem;

            //添加项不为空且与列表中最后一项操作类型相同时
            if (item != null && item.Action == actionItem.Action)
            {
                //检查操作是否只为颜色转换
                if (((item.Action == PhotoAction.ConvertSepia) ||
                     (item.Action == PhotoAction.ConvertGrayscale)))
                {
                    //  just return, don't want to reapply color conversion actions
                    return(false);
                }

                //如果只是以下类型的操作,则只需要重新设定操作后的值
                if (((item.Action == PhotoAction.Brightness) ||
                     ((item.Action == PhotoAction.Contrast) ||
                      ((item.Action == PhotoAction.Saturation) ||
                       (item.Action == PhotoAction.Gamma)))))
                {
                    // 更新当前操作的数值
                    item.Percent = actionItem.Percent;
                    // 更新滑块的值,以便于执行撤销操作时能够重置操作前的值
                    item.SetSliderValues(Global.SliderValues.Contrast,
                                         Global.SliderValues.Brightness,
                                         Global.SliderValues.Gamma,
                                         Global.SliderValues.Saturation);
                    return(false);
                }
            }
            //否则将新操作加入到列表中,并返回 true
            _list.Add(new ActionItem(actionItem));
            return(true);
        }
Пример #2
0
 //用于清除列表中的所有操作并将 _redoItem 设为空
 public void Clear()
 {
     _list.Clear();
     _redoItem = null;
 }
Пример #3
0
 public ActionEventArgs(PhotoAction action)
 {
     _actionItem = new ActionItem(action);
 }
Пример #4
0
        //  该方法对图片应用所有的颜色操作,以提供一个更加自然的用户体验。
        //  原始的操作顺序被忽略,方法中按照如下顺序对图片进行颜色操作:
        //  1) 灰度转化和褐色转化
        //  2) 对比度、亮度和饱和度调节
        //  3) gamma参数调节
        private void AdjustColor(ref Bitmap image)
        {
            int          brightness = 0;
            int          contrast   = 0;
            int          saturation = 0;
            int          gamma      = 0;
            ConvertColor convert    = ConvertColor.None;

            //  遍历操作列表找到每一个颜色操作的最后设定值
            for (int i = 0; i <= (Global.ActionList.Count - 1); i++)
            {
                ActionItem item = Global.ActionList.GetAt(i);
                switch (item.Action)
                {
                case PhotoAction.Brightness:
                    brightness = item.Percent;
                    break;

                case PhotoAction.Contrast:
                    contrast = item.Percent;
                    break;

                case PhotoAction.Saturation:
                    saturation = item.Percent;
                    break;

                case PhotoAction.Gamma:
                    gamma = item.Percent;
                    break;

                case PhotoAction.ConvertGrayscale:
                    convert = ConvertColor.Grayscale;
                    break;

                case PhotoAction.ConvertSepia:
                    convert = ConvertColor.Sepia;
                    break;
                }
            }
            //  执行颜色操作时更新进度条
            Global.Progress.Update(this, "Applying actions", 1, Global.ActionList.Count);
            //  只有当列表中还有一个或多个操作要执行时才更新
            if (((convert != ConvertColor.None) ||
                 ((contrast != 0) ||
                  ((brightness != 0) ||
                   (saturation != 0)))))
            {
                //  矩阵默认值(单位矩阵)
                float[][] matrix =
                {
                    new float[] { 1, 0, 0, 0, 0 },
                    new float[] { 0, 1, 0, 0, 0 },
                    new float[] { 0, 0, 1, 0, 0 },
                    new float[] { 0, 0, 0, 1, 0 },
                    new float[] { 0, 0, 0, 0, 1 }
                };
                //  灰度转化和褐色转化
                if ((convert == ConvertColor.Grayscale))
                {
                    matrix = PhotoHelper.CombineMatrix(matrix, PhotoHelper.GetGrayscaleMatrix());
                }
                if ((convert == ConvertColor.Sepia))
                {
                    matrix = PhotoHelper.CombineMatrix(matrix, PhotoHelper.GetSepiaMatrix());
                }
                //  对比度、亮度和饱和度调节
                if ((contrast != 0))
                {
                    matrix = PhotoHelper.CombineMatrix(matrix, PhotoHelper.GetContrastMatrix(contrast));
                }
                if ((brightness != 0))
                {
                    matrix = PhotoHelper.CombineMatrix(matrix, PhotoHelper.GetBrightnessMatrix(brightness));
                }
                if ((saturation != 0))
                {
                    matrix = PhotoHelper.CombineMatrix(matrix, PhotoHelper.GetSaturationMatrix(saturation));
                }
                //  对图片执行所有颜色操作
                PhotoHelper.AdjustUsingCustomMatrix(ref image, matrix);
            }
            //  gamma 参数调节,作为最后一个操作来执行
            if ((gamma != 0))
            {
                PhotoHelper.AdjustGamma(ref image, gamma);
            }
        }
Пример #5
0
 public ActionEventArgs(ActionItem actionItem)
 {
     _actionItem = actionItem;
 }