private void RefreshUI_DrawCropRect()
        {
            var listRect = kCropInfo.GetRectList();

            using (Graphics g = pictureBoxImage.CreateGraphics())
            {
                var pen = new Pen(Color.Red, 1f);

                for (int i = 0; i < listRect.Count; ++i)
                {
                    g.DrawLine(pen, listRect[i].LeftTop, listRect[i].LeftBottom);
                    g.DrawLine(pen, listRect[i].LeftBottom, listRect[i].RightBottom);
                    g.DrawLine(pen, listRect[i].RightBottom, listRect[i].RightTop);
                    g.DrawLine(pen, listRect[i].RightTop, listRect[i].LeftTop);
                }
            }
        }
Example #2
0
        private EnumFailedReason ExecCrop(int index, string Name, string path)
        {
            if (File.Exists(path) == false)
            {
                return(EnumFailedReason.FileNotExist);
            }

            var listRect = kCropInfo.GetRectList();

            if (listRect.Count == 0)
            {
                return(EnumFailedReason.RectCropInvalid);
            }

            var bitmapOrigin = Util.LoadBitmap(path);

            if (null == bitmapOrigin)
            {
                return(EnumFailedReason.BitmapLoadFailed);
            }

            for (int i = 0; i < listRect.Count; ++i)
            {
                var cropRectangle = new Rectangle(listRect[i].XMin, listRect[i].YMin, listRect[i].Width, listRect[i].Height);
                var bitmapClone   = bitmapOrigin.Clone(cropRectangle, bitmapOrigin.PixelFormat);
                if (null == bitmapClone)
                {
                    bitmapOrigin.Dispose();
                    return(EnumFailedReason.BitmapCloneFailed);
                }

                var fileName = string.Format("\\{0}_{1:D3}.png", Name, i);
                bitmapClone.Save(szSaveDirectoryPath + fileName, System.Drawing.Imaging.ImageFormat.Png);

                bitmapClone.Dispose();
            }

            bitmapOrigin.Dispose();
            return(EnumFailedReason.None);
        }