コード例 #1
0
        private void cropBannerBtn_Click(object sender, EventArgs e)
        {
            PropertyInfo pInfo = pbx.GetType().GetProperty("ImageRectangle",
                                                           System.Reflection.BindingFlags.Public |
                                                           System.Reflection.BindingFlags.NonPublic |
                                                           System.Reflection.BindingFlags.Instance);

            Rectangle rectangle = (Rectangle)pInfo.GetValue(pbx, null);

            var w = (float)rectangle.Width - rectangle.X;
            var h = (float)rectangle.Height;

            RectangleF selection2 = new RectangleF();

            selection2.X      = Math.Abs((_selection.X) / w);
            selection2.Y      = Math.Abs((_selection.Y - rectangle.Y) / h);
            selection2.Width  = Math.Min(1, Math.Abs((_selection.Width + _selection.X - rectangle.X) / w));
            selection2.Height = Math.Min(1, Math.Abs((_selection.Height + _selection.Y - rectangle.Y) / h));

            ResizeResult = new ResizeFormResult {
                IsCropBorders = true, RectF = selection2
            };

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
コード例 #2
0
        private void saveSize_btn_Click(object sender, EventArgs e)
        {
            var res = resizeControl1.GetResizeFormResult();

            ResizeResult = new ResizeFormResult {
                IsByPercintage = res.IsByPercintage, Size = res.Size, Rect = GetRectangleFromSelection()
            };

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
コード例 #3
0
        public static void ResizeAllFilesInDirectory(string path,
                                                     string folderSource,
                                                     string folderDestinition,
                                                     ResizeFormResult resizeResult)
        {
            var           sourceDirPath = Path.Combine(path, folderSource);
            DirectoryInfo dir           = new DirectoryInfo(sourceDirPath);
            var           files         = dir.GetFiles("*.jpg");

            if (files.Length > 0)
            {
                var dirSource      = Directory.CreateDirectory(sourceDirPath);
                var dirDestinition = Directory.CreateDirectory(Path.Combine(path, folderDestinition));
                foreach (var fi in files)
                {
                    try
                    {
                        Bitmap bmpImage = new Bitmap(fi.FullName);

                        var oldWidth  = bmpImage.Width;
                        var oldHeight = bmpImage.Height;

                        var newWidth  = oldWidth;
                        var newHeight = oldHeight;
                        if (resizeResult.IsByPercintage != null)
                        {
                            if (resizeResult.IsByPercintage ?? false)
                            {
                                newWidth  = (int)(oldWidth * resizeResult.Size / 100);
                                newHeight = (int)(oldHeight * resizeResult.Size / 100);
                            }
                            else
                            {
                                newWidth  = (int)resizeResult.Size;
                                newHeight = (int)(resizeResult.Size * ((decimal)oldHeight / oldWidth));
                            }
                        }

                        var resizedImage = ImageConverter.ResizeImage(bmpImage, newWidth, newHeight);
                        ImageConverter.SaveImage(resizedImage, fi, dirDestinition);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
        }