// Constructor, which saves away all of the important information.
	// We assume that the lock on the "graphics" object is held by the caller.
	internal GraphicsContainer(Graphics graphics)
			{
				// Push this container onto the stack.
				this.graphics = graphics;
				next = graphics.stackTop;
				graphics.stackTop = this;

				// Save the graphics state information.
				clip = graphics.Clip;
				if(clip != null)
				{
					clip = clip.Clone();
				}
				compositingMode = graphics.CompositingMode;
				compositingQuality = graphics.CompositingQuality;
				interpolationMode = graphics.InterpolationMode;
				pageScale = graphics.PageScale;
				pageUnit = graphics.PageUnit;
				pixelOffsetMode = graphics.PixelOffsetMode;
				renderingOrigin = graphics.RenderingOrigin;
				smoothingMode = graphics.SmoothingMode;
				textContrast = graphics.TextContrast;
				textRenderingHint = graphics.TextRenderingHint;
				if (graphics.transform == null)
				{
					transform = null;
				}
				else
				{
					transform = Matrix.Clone(graphics.transform);
				}
			}
Пример #2
0
        void drawTo(Graphics g)
        {
            // Background
            // Brush brushBackground = new SolidBrush(BackColor);
            // g.FillRectangle(brushBackground, this.ClientRectangle);

            Vector center = Vector.Zero;
            Vector size   = Vector.Zero;

            GraphicsUtil.TextPosition titlePosition = null;

            getWfCoords(ref center, ref size, ref titlePosition);
            if (titlePosition != null)
            {
                Brush titleBrush = new SolidBrush(_titleColor);
                titlePosition.drawText(g, _titleFont, titleBrush, _title);
            }

            Rectangle fr = VectorRect.FromCenterSize(center, size).rectangle;

            g.DrawRectangle(framePen, fr.Left - 1, fr.Top - 1, fr.Width + 2, fr.Height + 2);
            buildMap();
            updateBitmap();
            InterpolationMode imode = g.InterpolationMode;
            PixelOffsetMode   pmode = g.PixelOffsetMode;

            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            g.PixelOffsetMode   = PixelOffsetMode.Half;
            g.DrawImage(bmap, fr, 0, 0, bmap.Width, bmap.Height, GraphicsUnit.Pixel);
            g.InterpolationMode = imode;
            g.PixelOffsetMode   = pmode;
            // needsRedraw = false;
        }
Пример #3
0
        public static void DrawColorRectangle(Graphics g, Rectangle rect, Color color, bool drawBorder)
        {
            int        inflateAmt      = drawBorder ? -2 : 0;
            Rectangle  colorRectangle  = Rectangle.Inflate(rect, inflateAmt, inflateAmt);
            Brush      colorBrush      = new LinearGradientBrush(colorRectangle, Color.FromArgb(255, color), color, 90.0f, false);
            HatchBrush backgroundBrush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.FromArgb(191, 191, 191), Color.FromArgb(255, 255, 255));

            try
            {
                if (drawBorder)
                {
                    g.DrawRectangle(Pens.Black, rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
                    g.DrawRectangle(Pens.White, rect.Left + 1, rect.Top + 1, rect.Width - 3, rect.Height - 3);
                }

                PixelOffsetMode oldPOM = g.PixelOffsetMode;
                g.PixelOffsetMode = PixelOffsetMode.Half;
                g.FillRectangle(backgroundBrush, colorRectangle);
                g.FillRectangle(colorBrush, colorRectangle);
                g.PixelOffsetMode = oldPOM;
            }
            finally
            {
                backgroundBrush.Dispose();
                colorBrush.Dispose();
            }
        }
Пример #4
0
 public QualityModes()
 {
     CompositingQuality = CompositingQuality.HighQuality;
     InterpolationMode  = InterpolationMode.NearestNeighbor;
     SmoothingMode      = SmoothingMode.None;
     PixelOffsetMode    = PixelOffsetMode.Half;
 }
Пример #5
0
        internal GraphicsState(Graphics g, Matrix matrix, bool resetState)
        {
            _compositingMode    = g.CompositingMode;
            _compositingQuality = g.CompositingQuality;
            _clip = g.Clip;
            _interpolationMode = g.InterpolationMode;
            _pageScale         = g.PageScale;
            _pageUnit          = g.PageUnit;
            _pixelOffsetMode   = g.PixelOffsetMode;

            // FIXME: render orign is not implemented yet
            _renderingOrigin = g.RenderingOrigin;

            _smoothingMode = g.SmoothingMode;
            _transform     = g.Transform;

            _textContrast      = g.TextContrast;
            _textRenderingHint = g.TextRenderingHint;

            _clipMask = g.ClipMask;

            if (resetState)
            {
                ResetState(g, matrix);
            }
        }
Пример #6
0
        /// <summary>
        /// Draws the image.
        /// </summary>
        /// <param name="g"></param>
        protected void DrawImage(Graphics g)
        {
            InterpolationMode currentInterpolationMode = g.InterpolationMode;
            PixelOffsetMode   currentPixelOffsetMode   = g.PixelOffsetMode;

            g.InterpolationMode = this.InterpolationMode;

            // disable pixel offsets. Thanks to Rotem for the info.
            // http://stackoverflow.com/questions/14070311/why-is-graphics-drawimage-cropping-part-of-my-image/14070372#14070372
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;

            try
            {
                if (this.IsAnimating && !this.AnimationPaused)
                {
                    ImageAnimator.UpdateFrames(this._Image);
                }

                g.DrawImage(this._Image, this.GetImageViewPort(), this.GetSourceImageRegion(), GraphicsUnit.Pixel);
            }
            catch
            {
            }
            finally
            {
                g.PixelOffsetMode   = currentPixelOffsetMode;
                g.InterpolationMode = currentInterpolationMode;
            }
        }
Пример #7
0
        // Constructor, which saves away all of the important information.
        // We assume that the lock on the "graphics" object is held by the caller.
        internal GraphicsContainer(Graphics graphics)
        {
            // Push this container onto the stack.
            this.graphics     = graphics;
            next              = graphics.stackTop;
            graphics.stackTop = this;

            // Save the graphics state information.
            clip = graphics.Clip;
            if (clip != null)
            {
                clip = clip.Clone();
            }
            compositingMode    = graphics.CompositingMode;
            compositingQuality = graphics.CompositingQuality;
            interpolationMode  = graphics.InterpolationMode;
            pageScale          = graphics.PageScale;
            pageUnit           = graphics.PageUnit;
            pixelOffsetMode    = graphics.PixelOffsetMode;
            renderingOrigin    = graphics.RenderingOrigin;
            smoothingMode      = graphics.SmoothingMode;
            textContrast       = graphics.TextContrast;
            textRenderingHint  = graphics.TextRenderingHint;
            if (graphics.transform == null)
            {
                transform = null;
            }
            else
            {
                transform = Matrix.Clone(graphics.transform);
            }
        }
Пример #8
0
 public static void SetGraphicsModes(
     SmoothingMode smoothingMode, PixelOffsetMode pixelOffsetMode, InterpolationMode interpolationMode)
 {
     SmoothingMode     = smoothingMode;
     PixelOffsetMode   = pixelOffsetMode;
     InterpolationMode = interpolationMode;
 }
Пример #9
0
        /// <summary>
        /// Draw a string with the given size
        /// </summary>
        /// <param name="text">The string to draw</param>
        /// <param name="size">The font size of the string</param>
        /// <param name="location">The location to draw the string at</param>
        /// <param name="brush">The brush to draw the string with</param>
        /// <param name="centered">Set to true if you want to draw the string around instead of left-down from the location</param>
        public void DrawSizedString(string text, int size, PointF location, Brush brush, bool transform = true, bool centered = false)
        {
            SmoothingMode      tmpS = g.SmoothingMode;
            InterpolationMode  tmpI = g.InterpolationMode;
            CompositingMode    tmpM = g.CompositingMode;
            CompositingQuality tmpQ = g.CompositingQuality;
            PixelOffsetMode    tmpP = g.PixelOffsetMode;

            g.SmoothingMode      = SmoothingMode.AntiAlias;
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.CompositingMode    = CompositingMode.SourceOver;
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            Font       f = new Font("Tahoma", size);
            SizeF      s = g.MeasureString(text, f);
            RectangleF r = new RectangleF(centered ? new PointF(location.X - s.Width / 2, location.Y - s.Height / 2) : location, s);

            if (transform)
            {
                r = w2s(r);
            }
            g.DrawString(text, f, brush, r);
            g.PixelOffsetMode    = tmpP;
            g.CompositingQuality = tmpQ;
            g.CompositingMode    = tmpM;
            g.InterpolationMode  = tmpI;
            g.SmoothingMode      = tmpS;
        }
Пример #10
0
        internal GraphicsState(Graphics graphics, Matrix matrix, bool resetState)
        {
            _compositingMode    = graphics.CompositingMode;
            _compositingQuality = graphics.CompositingQuality;
            _clip              = graphics.ScaledClip;
            _baseClip          = graphics.NativeObject.getClip();
            _interpolationMode = graphics.InterpolationMode;
            _pageScale         = graphics.PageScale;
            _pageUnit          = graphics.PageUnit;
            _pixelOffsetMode   = graphics.PixelOffsetMode;

            // FIXME: render orign is not implemented yet
            //_renderingOrigin = new Point( g.RenderingOrigin.X, g.RenderingOrigin.Y );

            _smoothingMode = graphics.SmoothingMode;
            _transform     = graphics.Transform;
            _baseTransform = graphics.BaseTransform;

            _textContrast      = graphics.TextContrast;
            _textRenderingHint = graphics.TextRenderingHint;

            if (resetState)
            {
                ResetState(graphics, matrix);
            }
        }
Пример #11
0
        /// <summary>
        /// Paints gradient used in some dialogs
        /// </summary>
        /// <param name="g">Graphics</param>
        /// <param name="x">X</param>
        /// <param name="y">Y</param>
        /// <param name="width">Width</param>
        /// <param name="height">Height</param>
        /// <param name="gradientSize">Gradient size</param>
        /// <param name="alpha">Alpha</param>
        public static void PaintDirtGradient(Graphics g, int x, int y, int width, int height, int gradientSize, int alpha)
        {
            Region oldClip = g.Clip;

            g.SetClip(new Rectangle(x, y, width, height), CombineMode.Intersect);

            PixelOffsetMode oldPixelOffsetMode = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;

            SmoothingMode oldSmoothingMode = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            for (int i = 0; i < gradientSize; i += 3)
            {
                double curve = (Math.Sin((1.5 + ((double)i / gradientSize)) * Math.PI) + 1) / 2;
                using (Pen pen = new Pen(Color.FromArgb((int)((1 - curve) * 60) * alpha / 255, 0x55, 0x44, 0x44))) {
                    g.DrawLine(pen, width, i, width - gradientSize, i - gradientSize);
                }
            }

            g.Clip            = oldClip;
            g.PixelOffsetMode = oldPixelOffsetMode;
            g.SmoothingMode   = oldSmoothingMode;
        }
Пример #12
0
        /// <summary>
        /// </summary>
        /// <param name="paintParams"></param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="paintParams"/> is <see langword="null"/>.</para>
        /// </exception>
        public void DrawDropDownArrow(NuGenPaintParams paintParams)
        {
            if (paintParams == null)
            {
                throw new ArgumentNullException("paintParams");
            }

            Graphics          g      = paintParams.Graphics;
            Rectangle         bounds = paintParams.Bounds;
            NuGenControlState state  = paintParams.State;

            int x = bounds.Left + bounds.Width / 2;
            int y = bounds.Top + bounds.Height / 2 - 3;

            Point[] arrowPoints = new Point[] {
                new Point(x - 3, y),
                new Point(x + 2, y),
                new Point(x, y + 3)
            };

            using (SolidBrush sb = new SolidBrush(this.ColorManager.GetBorderColor(state)))
            {
                PixelOffsetMode oldPixelOffsetMode = g.PixelOffsetMode;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.FillPolygon(sb, arrowPoints);
                g.PixelOffsetMode = oldPixelOffsetMode;
            }
        }
Пример #13
0
        /// <summary>
        /// Method to perform preparatory work for symbilizing.
        /// </summary>
        /// <param name="g">The graphics object to symbolize upon</param>
        /// <param name="map">The map</param>
        /// <param name="aproximateNumberOfGeometries">An approximate number of geometries to symbolize</param>
        public virtual void Begin(Graphics g, Map map, int aproximateNumberOfGeometries)
        {
            _oldSmootingMode = g.SmoothingMode;
            _oldPixelOffsetMode = g.PixelOffsetMode;

            g.SmoothingMode = SmoothingMode;
            g.PixelOffsetMode = PixelOffsetMode;
        }
Пример #14
0
        /// <summary>
        /// Method to perform preparatory work for symbilizing.
        /// </summary>
        /// <param name="g">The graphics object to symbolize upon</param>
        /// <param name="map">The map</param>
        /// <param name="aproximateNumberOfGeometries">An approximate number of geometries to symbolize</param>
        public virtual void Begin(Graphics g, MapViewport map, int aproximateNumberOfGeometries)
        {
            _oldSmootingMode    = g.SmoothingMode;
            _oldPixelOffsetMode = g.PixelOffsetMode;

            g.SmoothingMode   = SmoothingMode;
            g.PixelOffsetMode = PixelOffsetMode;
        }
Пример #15
0
 public ImageComposerGDI() : base()
 {
     // default settings max quality
     CompositingMode    = CompositingMode.SourceOver;
     CompositingQuality = CompositingQuality.HighQuality;
     InterpolationMode  = InterpolationMode.HighQualityBicubic;
     SmoothingMode      = SmoothingMode.HighQuality;
     PixelOffsetMode    = PixelOffsetMode.HighQuality;
 }
Пример #16
0
 //-----------------------------------------------------
 public void SelectHighSpeed()
 {
     this.CompositingQuality = CompositingQuality.HighSpeed;
     this.InterpolationMode  = InterpolationMode.Low;
     this.PixelOffsetMode    = PixelOffsetMode.HighSpeed;
     this.SmoothingMode      = SmoothingMode.HighSpeed;
     this.TextRenderingHint  = TextRenderingHint.SingleBitPerPixel;
     return;
 }
 /// <summary>
 /// 释放资源
 /// </summary>
 /// <param name="disposing">释放托管资源为true,否则为false</param>
 protected override void Dispose(bool disposing)
 {
     if (this.m_Graphics != null)
     {
         this.m_Graphics.PixelOffsetMode = this.m_OldMode;
         this.m_Graphics = null;
     }
     this.m_OldMode = PixelOffsetMode.Default;
 }
Пример #18
0
 //-----------------------------------------------------
 public void SelectHighQuality()
 {
     this.CompositingQuality = CompositingQuality.HighQuality;
     this.InterpolationMode  = InterpolationMode.HighQualityBicubic;
     this.PixelOffsetMode    = PixelOffsetMode.HighQuality;
     this.SmoothingMode      = SmoothingMode.HighQuality;
     this.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
     return;
 }
Пример #19
0
 public ResizeImage(Size newSize)
 {
     NewSize            = newSize;
     InterpolationMode  = InterpolationMode.NearestNeighbor;
     GraphicsUnit       = GraphicsUnit.Pixel;
     SmoothingMode      = SmoothingMode.None;
     CompositingMode    = CompositingMode.SourceOver;
     CompositingQuality = CompositingQuality.HighSpeed;
     PixelOffsetMode    = PixelOffsetMode.None;
 }
Пример #20
0
        public static Stream CreateCropedImageFile(Stream originalStream, double x, double y, double q, ImageFormat outputFormat, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetMode, double verticalDiff, double horizontalDiff)
        {


            if (originalStream == null)
                return new MemoryStream();

            Stream newMemoryStream;

            using (var originalImage = System.Drawing.Image.FromStream(originalStream))
            {
                using (var bmp = new Bitmap((int)x, (int)y))
                {
                    double verticalOffset = verticalDiff;
                    double horizontalOffset = horizontalDiff;
                    if(horizontalDiff == double.MaxValue)
                    {
                        horizontalOffset = originalImage.Width - x;
                    }else if(horizontalDiff < 0)
                    {
                        horizontalOffset = (originalImage.Width - x)/2;
                    }

                    if(horizontalOffset<0)
                        horizontalOffset = 0;

                    if (verticalDiff == double.MaxValue)
                    {
                        verticalOffset = originalImage.Height - y;
                    }else if(verticalDiff < 0)
                    {
                        verticalOffset = (originalImage.Height - y)/2;
                    }

                    if(verticalOffset<0)
                        verticalOffset = 0;

                    bmp.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution);
                    using (var graphic = Graphics.FromImage(bmp))
                    {
                        graphic.SmoothingMode = smoothingMode;
                        graphic.InterpolationMode = interpolationMode;
                        graphic.PixelOffsetMode = pixelOffsetMode;
                        graphic.DrawImage(originalImage, new Rectangle(0, 0, (int)x, (int)y), (int)horizontalOffset, (int)verticalOffset, (int)x, (int)y, GraphicsUnit.Pixel);
                        newMemoryStream = new MemoryStream();
                        bmp.Save(newMemoryStream, originalImage.RawFormat);
                        
                        if(bmp != null)
                            bmp.Dispose();
                    }
                }
            }
            newMemoryStream.Position = 0;
            return newMemoryStream;
        }
Пример #21
0
 //-----------------------------------------------------
 public void CopyFrom(Graphics Graphics_in)
 {
     this.CompositingMode    = Graphics_in.CompositingMode;
     this.CompositingQuality = Graphics_in.CompositingQuality;
     this.InterpolationMode  = Graphics_in.InterpolationMode;
     this.PixelOffsetMode    = Graphics_in.PixelOffsetMode;
     this.SmoothingMode      = Graphics_in.SmoothingMode;
     this.TextRenderingHint  = Graphics_in.TextRenderingHint;
     this.TextContrast       = Graphics_in.TextContrast;
     return;
 }
Пример #22
0
 //-----------------------------------------------------
 public void SelectDefault()
 {
     this.CompositingMode    = CompositingMode.SourceCopy;
     this.CompositingQuality = CompositingQuality.Default;
     this.InterpolationMode  = InterpolationMode.Default;
     this.PixelOffsetMode    = PixelOffsetMode.Default;
     this.SmoothingMode      = SmoothingMode.Default;
     this.TextRenderingHint  = TextRenderingHint.SystemDefault;
     this.TextContrast       = 4;
     return;
 }
Пример #23
0
        private void DrawSelectionOutline(Graphics g, PdnGraphicsPath outline)
        {
            if (outline == null)
            {
                return;
            }

            if (outlinePen1 == null)
            {
                outlinePen1           = new Pen(Color.FromArgb(160, Color.Black), 1.0f);
                outlinePen1.Alignment = PenAlignment.Outset;
                outlinePen1.LineJoin  = LineJoin.Bevel;
                outlinePen1.Width     = -1;
            }

            if (outlinePen2 == null)
            {
                outlinePen2             = new Pen(Color.White, 1.0f);
                outlinePen2.Alignment   = PenAlignment.Outset;
                outlinePen2.LineJoin    = LineJoin.Bevel;
                outlinePen2.MiterLimit  = 2;
                outlinePen2.Width       = -1;
                outlinePen2.DashStyle   = DashStyle.Dash;
                outlinePen2.DashPattern = new float[] { 4, 4 };
                outlinePen2.Color       = Color.White;
                outlinePen2.DashOffset  = 4.0f;
            }

            PixelOffsetMode oldPOM = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.None;

            SmoothingMode oldSM = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            outline.Draw(g, outlinePen1);

            float offset = (float)((double)dancingAntsT / OwnerList.ScaleFactor.Ratio);

            outlinePen2.DashOffset += offset;

            if (whiteOpacity != 0)
            {
                outlinePen2.Color = Color.FromArgb(whiteOpacity, Color.White);
                outline.Draw(g, outlinePen2);
            }

            outlinePen2.DashOffset -= offset;

            g.SmoothingMode   = oldSM;
            g.PixelOffsetMode = oldPOM;
        }
Пример #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NuGenGrfxMode"/> class.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="grfx"/> is <see langword="null"/>.</para>
        /// </exception>
        public NuGenGrfxMode(Graphics grfx)
        {
            if (grfx == null)
            {
                throw new ArgumentNullException("grfx");
            }

            _grfx = grfx;

            _oldPixelOffsetMode   = _grfx.PixelOffsetMode;
            _oldSmoothingMode     = _grfx.SmoothingMode;
            _oldTextRenderingHint = _grfx.TextRenderingHint;
        }
Пример #25
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenGrfxMode"/> class.
		/// </summary>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="grfx"/> is <see langword="null"/>.</para>
		/// </exception>
		public NuGenGrfxMode(Graphics grfx)
		{
			if (grfx == null)
			{
				throw new ArgumentNullException("grfx");
			}

			_grfx = grfx;

			_oldPixelOffsetMode = _grfx.PixelOffsetMode;
			_oldSmoothingMode = _grfx.SmoothingMode;
			_oldTextRenderingHint = _grfx.TextRenderingHint;
		}
Пример #26
0
 public CustomPbox()
 {
     SetStyle(ControlStyles.AllPaintingInWmPaint
              | ControlStyles.UserPaint
              | ControlStyles.OptimizedDoubleBuffer
              | ControlStyles.ResizeRedraw, true);
     ZoomDelta                = 0.1f;
     AllowUserDrag            = false;
     AllowUserZoom            = false;
     InterpolationMode        = InterpolationMode.Bicubic;
     InterpolationModeZoomOut = InterpolationMode.Bilinear;
     PixelOffsetMode          = PixelOffsetMode.HighQuality;
 }
Пример #27
0
        public static void DrawImageEx(this Graphics g, Image i, RectangleF r, byte alpha, bool grayscaled)
        {
            if (alpha == 0)
            {
                return;
            }

            PixelOffsetMode oldPOM = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;

            PointF ulCorner = new PointF(r.Left, r.Top);
            PointF urCorner = new PointF(r.Right, r.Top);
            PointF llCorner = new PointF(r.Left, r.Bottom);

            PointF[] destPoints = { ulCorner, urCorner, llCorner };

            if (alpha == 0xff && !grayscaled)
            {
                g.DrawImage(i, destPoints, new RectangleF(0, 0, i.Width, i.Height), GraphicsUnit.Pixel);
                return;
            }

            ColorMatrix colorMatrix;

            if (grayscaled)
            {
                colorMatrix = new ColorMatrix(new[] {
                    new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                    new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                    new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                    new float[] { 0, 0, 0, alpha / 255f, 0 },
                    new float[] { 0, 0, 0, 0, 1 }
                });
            }
            else
            {
                colorMatrix = new ColorMatrix(new[] {
                    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, alpha / 255f, 0 },
                    new float[] { 0, 0, 0, 0, 1 }
                });
            }
            using (ImageAttributes imageAttributes = new ImageAttributes()) {
                imageAttributes.SetColorMatrix(colorMatrix);
                g.DrawImage(i, destPoints, new RectangleF(0, 0, i.Width, i.Height), GraphicsUnit.Pixel, imageAttributes);
            }
            g.PixelOffsetMode = oldPOM;
        }
Пример #28
0
 // Constructor.
 protected ToolkitGraphicsBase(IToolkit toolkit)
 {
     this.toolkit       = toolkit;
     clip               = null;
     compositingMode    = CompositingMode.SourceOver;
     compositingQuality = CompositingQuality.Default;
     interpolationMode  = InterpolationMode.Default;
     pixelOffsetMode    = PixelOffsetMode.Default;
     renderingOrigin    = new Point(0, 0);
     smoothingMode      = SmoothingMode.Default;
     textContrast       = 4;
     textRenderingHint  = TextRenderingHint.SystemDefault;
     dirtyFlags         = DirtyFlags.All;
 }
	// Constructor.
	protected ToolkitGraphicsBase(IToolkit toolkit)
			{
				this.toolkit = toolkit;
				clip = null;
				compositingMode = CompositingMode.SourceOver;
				compositingQuality = CompositingQuality.Default;
				interpolationMode = InterpolationMode.Default;
				pixelOffsetMode = PixelOffsetMode.Default;
				renderingOrigin = new Point(0, 0);
				smoothingMode = SmoothingMode.Default;
				textContrast = 4;
				textRenderingHint = TextRenderingHint.SystemDefault;
				dirtyFlags = DirtyFlags.All;
			}
Пример #30
0
        public static void Draw(Image image, float x, float y, Graphics g, TransformParams t)
        {
            Utils.ThrowException(g == null ? new ArgumentNullException("g") : null);
            Utils.ThrowException(t == null ? new ArgumentNullException("t") : null);
            // TODO: throw other exceptions
            float           width           = t.Transform(image.Width);
            float           height          = t.Transform(image.Height);
            Vector2DF       pos             = t.Transform(new Vector2DF(x, y));
            PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;
            g.DrawImage(image, pos.X, pos.Y, width, height);
            g.PixelOffsetMode = pixelOffsetMode;
        }
Пример #31
0
        static ImageFinder()
        {
            Size sourceImageSize = new Size(2560, 2560);
            Size targetImageSize = new Size(256, 256);

            PixelFormat           = PixelFormat.Format24bppRgb;
            InterpolationMode     = InterpolationMode.HighQualityBicubic;
            PixelOffsetMode       = PixelOffsetMode.HighQuality;
            SourceImageContainer  = new ImageContainer(sourceImageSize);
            TargetImageContainer  = new ImageContainer(targetImageSize);
            SourceHashedImageData = new HashedImageData[sourceImageSize.Width, sourceImageSize.Height];
            TargetHashedImageData = new HashedImageData[targetImageSize.Width, targetImageSize.Height];
            LastMatches           = new List <Match>();
        }
Пример #32
0
        public static sd2.PixelOffsetMode ToSD(this PixelOffsetMode mode)
        {
            switch (mode)
            {
            case PixelOffsetMode.None:
                return(sd2.PixelOffsetMode.None);

            case PixelOffsetMode.Half:
                return(sd2.PixelOffsetMode.Half);

            default:
                throw new NotSupportedException();
            }
        }
Пример #33
0
        private static Image Resize(Image originalImage, int newWidth, int newHeight, CompositingQuality compositingQuality, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetmode)
        {
            Image result = new Bitmap(newWidth, newHeight);
            using (var graphic = Graphics.FromImage(result))
            {
                graphic.CompositingQuality = compositingQuality;
                graphic.SmoothingMode = smoothingMode;
                graphic.InterpolationMode = interpolationMode;
                graphic.PixelOffsetMode = pixelOffsetmode;

                Rectangle rectangle = new Rectangle(0, 0, newWidth, newHeight);
                graphic.DrawImage(originalImage, rectangle);
                return result;
            }
        }
Пример #34
0
 /// <summary>
 /// Creates a new instance using the specified settings.
 /// </summary>
 /// <param name="compositingQuality"></param>
 /// <param name="interpolationMode"></param>
 /// <param name="pixelOffsetMode"></param>
 /// <param name="smoothingMode"></param>
 /// <param name="textRenderingHint"></param>
 /// <param name="textContrast"></param>
 internal GraphicsSettings(
     CompositingQuality compositingQuality,
     InterpolationMode interpolationMode,
     PixelOffsetMode pixelOffsetMode,
     SmoothingMode smoothingMode,
     TextRenderingHint textRenderingHint,
     int textContrast)
 {
     _compositingQuality = compositingQuality;
     _interpolationMode  = interpolationMode;
     _pixelOffsetMode    = pixelOffsetMode;
     _smoothingMode      = smoothingMode;
     _textContrast       = textContrast;
     _textRenderingHint  = textRenderingHint;
 }
Пример #35
0
        /// <summary>
        ///     Fill a rectangular area with the linear gradient.
        /// </summary>
        /// <param name="g">Graphics object.</param>
        /// <param name="r">Rectangle area to fill.</param>
        /// <param name="backBrush">Brush to fill the background before filling with the linear gradient.</param>
        /// <exception cref="System.ArgumentNullException">
        ///		Thrown if <paramref name="g" /> is null.
        ///	</exception>
        public void FillRectangle(Graphics g, Rectangle r, Brush backBrush)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            g.FillRectangle(backBrush, r);

            PixelOffsetMode oldMode = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;
            g.FillRectangle(gradientBrush, r);
            g.PixelOffsetMode = oldMode;
        }
Пример #36
0
 public ZoomPictureBox()
 {
     //drawing optimization
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
     //default settings
     ZoomDelta                = 0.1f;
     AllowUserDrag            = true;
     AllowUserZoom            = true;
     LocationOnImage          = new Point();
     InterpolationMode        = InterpolationMode.Bicubic;
     InterpolationModeZoomOut = InterpolationMode.Bilinear;
     PixelOffsetMode          = PixelOffsetMode.HighQuality;
     pen           = new Pen(Color.Black, 2);
     pen.DashStyle = DashStyle.DashDot;
 }
Пример #37
0
        public static Stream CreateResizedImageFile(Stream originalStream, double x, double y, double q, bool allowStretching, ImageFormat outputFormat, SmoothingMode smoothingMode, InterpolationMode interpolationMode, PixelOffsetMode pixelOffsetMode)
        {
            if (originalStream == null)
                return new MemoryStream(); ;

            Stream stream;

            using (Bitmap img = new Bitmap(originalStream))
            {
                // if the size of the original image is the same as the specified resizing size then we just return the original stream
                if (img.Width == System.Convert.ToInt32(x) && img.Height == System.Convert.ToInt32(y)) return originalStream;

                double iw = img.Width; double ih = img.Height;
                double w = 0; double h = 0;
                if (allowStretching)
                {
                    w = (x == 0 ? img.Width : x);
                    h = (y == 0 ? img.Height : y);
                }
                else
                {
                    GetRealXY(iw, ih, x, y, out w, out h);
                }
                Bitmap newimg;
                if (w == 0 || h == 0)
                {
                    newimg = new Bitmap(img);
                }
                else
                {
                    newimg = new Bitmap(img, (int)w, (int)h);
                    using (Graphics gr = Graphics.FromImage(newimg))
                    {
                        gr.SmoothingMode = smoothingMode;
                        gr.InterpolationMode = interpolationMode;
                        gr.PixelOffsetMode = pixelOffsetMode;
                        gr.DrawImage(img, new Rectangle(0, 0, (int)w, (int)h));

                    }
                }
                stream = new MemoryStream();
                newimg.Save(stream, outputFormat);
                if (newimg != null)
                    newimg.Dispose();
            }
            stream.Position = 0;
            return stream;
        }
Пример #38
0
        public static Bitmap GdiResize(Image photo, int width, int height,
            InterpolationMode interpolationMode = InterpolationMode.HighQualityBicubic,
            SmoothingMode smoothingMode = SmoothingMode.HighQuality,
            PixelOffsetMode pixelMode = PixelOffsetMode.HighQuality,
            CompositingQuality compositingQuality = CompositingQuality.HighQuality,
            CompositingMode compositingMode = CompositingMode.SourceOver
            )
        {
            var resized = new Bitmap(width, height);
            using (var graphics = Graphics.FromImage(resized)) {
                graphics.CompositingQuality = compositingQuality;
                graphics.InterpolationMode = interpolationMode;
                graphics.CompositingMode = compositingMode;
                graphics.SmoothingMode = smoothingMode;
                graphics.PixelOffsetMode = pixelMode;

                graphics.DrawImage(photo, 0, 0, width, height);
            }
            return resized;
        }
        public static Metafile CreateMetafile(
            this BitmapSource bitmap, 
            double horizontalScale = 1.0,
            double verticalScale = 1.0,
            EmfType emf = EmfType.EmfOnly,
            SmoothingMode smoothingMode = SmoothingMode.HighQuality,
            InterpolationMode interpolationMode = InterpolationMode.HighQualityBicubic,
            PixelOffsetMode pixelOffsetMode = PixelOffsetMode.HighQuality,
            CompositingQuality compositingQuality = CompositingQuality.HighQuality)
        {
            var mf = (Metafile)null;

            using (System.Drawing.Graphics cx = System.Drawing.Graphics.FromHwndInternal(IntPtr.Zero))
            {
                mf = new Metafile(new MemoryStream(), cx.GetHdc(), emf);

                using (var g = System.Drawing.Graphics.FromImage(mf))
                {
                    var img = bitmap.ToBitmap();

                    g.SmoothingMode = smoothingMode;
                    g.InterpolationMode = interpolationMode;
                    g.PixelOffsetMode = pixelOffsetMode;
                    g.CompositingQuality = compositingQuality;

                    var rect =
                        new System.Drawing.RectangleF(
                            0,
                            0,
                            img.PhysicalDimension.Width * (float)horizontalScale,
                            img.PhysicalDimension.Height * (float)verticalScale);

                    g.DrawImage(img, rect);
                }
            }

            return mf;
        }
		internal GraphicsState(Graphics graphics, Matrix matrix, bool resetState)
		{
			_compositingMode = graphics.CompositingMode;
			_compositingQuality = graphics.CompositingQuality;
			_clip = graphics.ScaledClip;
			_baseClip = graphics.NativeObject.getClip();
			_interpolationMode = graphics.InterpolationMode;
			_pageScale = graphics.PageScale;
			_pageUnit = graphics.PageUnit;
			_pixelOffsetMode = graphics.PixelOffsetMode;
			
			// FIXME: render orign is not implemented yet
			//_renderingOrigin = new Point( g.RenderingOrigin.X, g.RenderingOrigin.Y );

			_smoothingMode = graphics.SmoothingMode;
			_transform = graphics.Transform;
			_baseTransform = graphics.BaseTransform;

			_textContrast = graphics.TextContrast;
			_textRenderingHint = graphics.TextRenderingHint;

			if (resetState)
				ResetState(graphics, matrix);
		}
Пример #41
0
 internal static extern GpStatus GdipGetPixelOffsetMode(GpGraphics graphics, out PixelOffsetMode pixelOffsetMode);
Пример #42
0
 internal static extern int GdipGetPixelOffsetMode(HandleRef graphics, out PixelOffsetMode pixelOffsetMode);
Пример #43
0
 public void saveGraphics(NetGraphics netG)
 {
     if (netG == null )
     {
         return;
     }
     if (netG.g != null )
     {
         this.Transform = netG.g.Transform;
         this.Clip = netG.g.Clip;
         this.SmoothingMode = netG.g.SmoothingMode;
         this.PixelOffsetMode = netG.g.PixelOffsetMode;
         this.TextRenderingHint = netG.g.TextRenderingHint;
         this.InterpolationMode = netG.g.InterpolationMode;
         this.CompositingMode = netG.g.CompositingMode;
         savedGraphics = true;
     }
     if (netG.pen != null && netG.brush != null)
     {
         pen = (Pen)netG.pen.Clone();
         brush = (Brush)netG.brush.Clone();
     }
 }
Пример #44
0
 public static extern GpStatus GdipSetPixelOffsetMode(GpGraphics graphics, PixelOffsetMode pixelOffsetMode);
Пример #45
0
		internal static extern Status GdipGetPixelOffsetMode(IntPtr graphics, out PixelOffsetMode pixelOffsetMode);
Пример #46
0
 /// <summary>
 /// Creates a new instance using the specified settings.
 /// </summary>
 /// <param name="compositingQuality"></param>
 /// <param name="interpolationMode"></param>
 /// <param name="pixelOffsetMode"></param>
 /// <param name="smoothingMode"></param>
 /// <param name="textRenderingHint"></param>
 /// <param name="textContrast"></param>
 internal GraphicsSettings(
         CompositingQuality compositingQuality,
         InterpolationMode interpolationMode,
         PixelOffsetMode pixelOffsetMode,
         SmoothingMode smoothingMode,
         TextRenderingHint textRenderingHint,
         int textContrast)
 {
     _compositingQuality = compositingQuality;
     _interpolationMode = interpolationMode;
     _pixelOffsetMode = pixelOffsetMode;
     _smoothingMode = smoothingMode;
     _textContrast = textContrast;
     _textRenderingHint = textRenderingHint;
 }
Пример #47
0
        /// <summary>
        /// Generate a new image based on the given image. Size is specified by caller.
        /// InterpolationMode,SmoothingMode and PixelOffsetMode used to render the new image
        /// are specified by the caller.		/// </summary>
        /// <param name="sourceImage"></param>
        /// <param name="newWidth"></param>
        /// <param name="newHeight"></param>
        /// <param name="imode"></param>
        /// <param name="smode"></param>
        /// <param name="pomode"></param>
        /// <returns></returns>
        public static Image CreateImage(Image sourceImage, int newWidth, int newHeight, InterpolationMode imode, SmoothingMode smode, PixelOffsetMode pomode)
        {
            try
            {

                // create the new image

                Bitmap newImage = new Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // get graphics object containing the new image

                using (Graphics g = Graphics.FromImage(newImage))
                {

                    // set the interpolation mode of the graphics

                    g.InterpolationMode = imode;

                    // set smoothing mode

                    g.SmoothingMode = smode;

                    // set pixel offset mode

                    g.PixelOffsetMode = pomode;

                    // draw into the image

                    g.DrawImage(sourceImage, new Rectangle(0, 0, newWidth, newHeight));

                }

                // return the new image

                return newImage;

            }
            catch (Exception)
            {

                return null;
            }
        }