示例#1
0
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Rectangle region = new Rectangle(0, 0, ImgSrc.Width, ImgSrc.Height);

            if (Params.ContainsKey("CropRegion"))
            {
                region = (Rectangle)Params["CropRegion"].Value;
            }

            if (Params.ContainsKey("CropSide"))
            {
                var side = (SideType)Params["CropSide"].Value;
                region = Rectangle.Round(AddinUtils.AdjustRegion(region, ImgSrc, side));
            }

            if (region.Width > 0 && region.Height > 0)
            {
                Accord.Imaging.Filters.Crop filter = new Accord.Imaging.Filters.Crop(region);
                Bitmap dst = filter.Apply(AddinUtils.CloneImage(ImgSrc) as Bitmap);
                AddinUtils.CloneExif(ImgSrc, dst);
                return(dst);
            }
            else
            {
                return(ImgSrc);
            }
        }
示例#2
0
        private void btnMode_Click(object sender, EventArgs e)
        {
            if (sender == btnModeSelection)
            {
                grpCropSide.Enabled   = false;
                grpCropAspect.Enabled = true;
                cropMode = CropMode.Selection;
            }
            else if (sender == btnModeTrans || sender == btnModeTopLeft || sender == btnModeBottomRight)
            {
                grpCropSide.Enabled   = true;
                grpCropAspect.Enabled = false;

                if ((sender as RadioButton).Checked)
                {
                    if (sender == btnModeTrans)
                    {
                        opaqueMode = ContentMaskMode.Alpha;
                        cropMode   = CropMode.Transparency;
                    }
                    else if (sender == btnModeTopLeft)
                    {
                        opaqueMode = ContentMaskMode.TopLeft;
                        cropMode   = CropMode.TopLeft;
                    }
                    else if (sender == btnModeBottomRight)
                    {
                        opaqueMode = ContentMaskMode.BottomRight;
                        cropMode   = CropMode.BottomRight;
                    }

                    selectionSrc = AddinUtils.AdjustRegion(AddinUtils.GetContentBound(addin.ImageData, opaqueMode), addin.ImageData, cropSide);
                    imgPreview.SelectionRegion = AddinUtils.RemapRegion(selectionSrc, addin.ImageData, thumb);
                }
            }
            else if (sender == btnModeAspect)
            {
                grpCropSide.Enabled   = false;
                grpCropAspect.Enabled = true;
                cropMode  = CropMode.AspectRatio;
                selection = MakeAspectRegion(thumb.Size, selection, cropAspectFactor);
                imgPreview.SelectionRegion = selection;
            }
        }
示例#3
0
        private void chkSide_Click(object sender, EventArgs e)
        {
            cropSide = SideType.None;

            if (chkSideL.Checked)
            {
                cropSide |= SideType.Left;
            }
            if (chkSideR.Checked)
            {
                cropSide |= SideType.Right;
            }
            if (chkSideT.Checked)
            {
                cropSide |= SideType.Top;
            }
            if (chkSideB.Checked)
            {
                cropSide |= SideType.Bottom;
            }

            selectionSrc = AddinUtils.AdjustRegion(AddinUtils.GetOpaqueBound(addin.ImageData, opaqueMode), addin.ImageData, cropSide);
            imgPreview.SelectionRegion = AddinUtils.RemapRegion(selectionSrc, addin.ImageData, thumb);
        }