Example #1
0
        void Command_Image_Rotate(ImageRotateDialog.Result result)
        {
            var variables = GetVariables();
            var angle     = new NEExpression(result.AngleExpression).Evaluate <float>(variables, "deg");

            var bitmap = GetBitmap();
            var path   = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddRectangle(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height));
            var matrix = new System.Drawing.Drawing2D.Matrix();

            matrix.Rotate(angle);
            var rect         = path.GetBounds(matrix);
            var resultBitmap = new System.Drawing.Bitmap((int)rect.Width, (int)rect.Height, bitmap.PixelFormat);

            using (var g = System.Drawing.Graphics.FromImage(resultBitmap))
            {
                g.TranslateTransform(-rect.X, -rect.Y);
                g.RotateTransform(angle);
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                g.DrawImageUnscaled(bitmap, 0, 0);
            }

            Replace(new List <Range> {
                FullRange
            }, new List <string> {
                Coder.BitmapToString(resultBitmap)
            });
            SetSelections(new List <Range> {
                BeginRange
            });
        }
Example #2
0
        void Command_Image_Size(ImageSizeDialog.Result result)
        {
            var variables = GetVariables();
            var width     = new NEExpression(result.WidthExpression).Evaluate <int>(variables);
            var height    = new NEExpression(result.HeightExpression).Evaluate <int>(variables);

            var bitmap       = GetBitmap();
            var resultBitmap = new System.Drawing.Bitmap(width, height, bitmap.PixelFormat);

            resultBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
            using (var graphics = System.Drawing.Graphics.FromImage(resultBitmap))
            {
                graphics.CompositingMode    = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = result.InterpolationMode;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                using (var wrapMode = new System.Drawing.Imaging.ImageAttributes())
                {
                    wrapMode.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
                    graphics.DrawImage(bitmap, new System.Drawing.Rectangle(0, 0, width, height), 0, 0, bitmap.Width, bitmap.Height, System.Drawing.GraphicsUnit.Pixel, wrapMode);
                }
            }

            Replace(new List <Range> {
                FullRange
            }, new List <string> {
                Coder.BitmapToString(resultBitmap)
            });
            SetSelections(new List <Range> {
                BeginRange
            });
        }
Example #3
0
        void Command_Image_Crop(ImageCropDialog.Result result)
        {
            var variables = GetVariables();
            var destX     = new NEExpression(result.XExpression).Evaluate <int>(variables);
            var destY     = new NEExpression(result.YExpression).Evaluate <int>(variables);
            var newWidth  = new NEExpression(result.WidthExpression).Evaluate <int>(variables);
            var newHeight = new NEExpression(result.HeightExpression).Evaluate <int>(variables);

            if ((newWidth <= 0) || (newHeight <= 0))
            {
                throw new Exception("Width and height must be greater than 0");
            }

            var bitmap = GetBitmap();
            var srcX   = 0;
            var srcY   = 0;
            var width  = bitmap.Width;
            var height = bitmap.Height;

            if (destX < 0)
            {
                width += destX;
                srcX  -= destX;
                destX  = 0;
            }
            if (destY < 0)
            {
                height += destY;
                srcY   -= destY;
                destY   = 0;
            }
            width  = Math.Min(width, newWidth - destX);
            height = Math.Min(height, newHeight - destY);

            var resultBitmap = new System.Drawing.Bitmap(newWidth, newHeight, bitmap.PixelFormat);

            resultBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
            using (var graphics = System.Drawing.Graphics.FromImage(resultBitmap))
                using (var wrapMode = new System.Drawing.Imaging.ImageAttributes())
                {
                    graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb((int)Colorer.StringToValue(result.FillColor))), new System.Drawing.Rectangle(System.Drawing.Point.Empty, resultBitmap.Size));
                    graphics.DrawImage(bitmap, new System.Drawing.Rectangle(destX, destY, width, height), new System.Drawing.Rectangle(srcX, srcY, width, height), System.Drawing.GraphicsUnit.Pixel);
                }

            Replace(new List <Range> {
                FullRange
            }, new List <string> {
                Coder.BitmapToString(resultBitmap)
            });
            SetSelections(new List <Range> {
                BeginRange
            });
        }
Example #4
0
        void Flip(System.Drawing.RotateFlipType type)
        {
            var bitmap = Coder.StringToBitmap(AllText);

            bitmap.RotateFlip(type);
            Replace(new List <Range> {
                FullRange
            }, new List <string> {
                Coder.BitmapToString(bitmap)
            });
            SetSelections(new List <Range> {
                BeginRange
            });
        }
Example #5
0
        void Command_Image_GrabImage(ImageGrabImageDialog.Result result)
        {
            var variables = GetVariables();
            var x         = new NEExpression(result.GrabX).EvaluateList <int>(variables, Selections.Count());
            var y         = new NEExpression(result.GrabY).EvaluateList <int>(variables, Selections.Count());
            var width     = new NEExpression(result.GrabWidth).EvaluateList <int>(variables, Selections.Count());
            var height    = new NEExpression(result.GrabHeight).EvaluateList <int>(variables, Selections.Count());

            var strs = new List <string>();

            for (var ctr = 0; ctr < x.Count; ++ctr)
            {
                using (var image = new System.Drawing.Bitmap(width[ctr], height[ctr], System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    using (var dest = System.Drawing.Graphics.FromImage(image))
                        dest.CopyFromScreen(x[ctr], y[ctr], 0, 0, image.Size);
                    strs.Add(Coder.BitmapToString(image));
                }
            }
            ReplaceSelections(strs);
        }