// 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
		public Overview()
		{
			// Set some styles
			SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			SetStyle(ControlStyles.DoubleBuffer, true);
			SetStyle(ControlStyles.ResizeRedraw, true);
			SetStyle(ControlStyles.UserPaint, true);

			document		= null;
			options			= new MindFusion.FlowChartX.PrintOptions(null);
			smoothMode		= SmoothingMode.Default;
			scaleFactor		= 30;
			fitToAll		= false;
			marginalColor	= Color.FromArgb(35, Color.Black);

			// Initialize rendering options
			options.EnableShadows			= true;
			options.EnableImages			= true;
			options.EnableInterior			= true;
			options.EnableBackground		= true;
			options.EnableBackgroundImage	= true;
			options.EnableText				= true;
			options.PaintControls			= true;

			// Auto scroll
			autoScroll = true;
			autoScrDX = autoScrDY = 0;
		}
예제 #3
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;
        }
예제 #4
0
파일: DSView.cs 프로젝트: 28427328/SQCharts
 public DSView(Pad pad, TimeSeries series, Color color, SearchOption option, SmoothingMode smoothing)
     : base(pad)
 {
     this.series = series;
     Option = option;
     Color = color;
     SmoothingMode = smoothing;
     ToolTipFormat = "{0}\n{2} - {3:F*}".Replace("*", pad.Chart.LabelDigitsCount.ToString());
 }
예제 #5
0
파일: DSView.cs 프로젝트: heber/FreeOQ
		public DSView(Pad pad, DoubleSeries series, Color color, EIndexOption option, SmoothingMode smoothing)
			: base(pad)
		{
			this.mainSeries = series;
			this.option = option;
			this.KNRy1kSrcC = color;
			this.IXfyvDxxVL = smoothing;
			this.ToolTipFormat = "toool";
//			this.ToolTipFormat = this.toolTipFormat.Replace(FJDHryrxb1WIq5jBAt.mT707pbkgT(2828), pad.Chart.LabelDigitsCount.ToString());
		}
예제 #6
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;
        }
예제 #7
0
 /// <summary>
 /// This constructor takes on some default values, and assumes that it
 /// has no other underlying symblizer to reference.
 /// </summary>
 public FeatureSymbolizerOld()
 {
     // Use the property to also set FillColor
     _fillColor = SymbologyGlobal.RandomColor();
     _fillBrush = new SolidBrush(_fillColor);
     _opacity = 1f;
     _isVisible = true; // This is boolean and should be true by default
     _smoothing = SmoothingMode.AntiAlias;
     LegendType = LegendType.Symbol;
     base.LegendSymbolMode = SymbolMode.Symbol;
 }
예제 #8
0
 public static void RenderText(Graphics gr, string text, int x, Color fillColor, Color textColor, Color traceColor, int maxHeight = -1, int y = 4, Font font = null, bool center = false, InterpolationMode interpolationMode = InterpolationMode.High, SmoothingMode smoothingMode = SmoothingMode.HighQuality)
 {
     gr.InterpolationMode = interpolationMode;
     gr.SmoothingMode = smoothingMode;
     gr.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
     gr.CompositingQuality = CompositingQuality.HighQuality;
     FontFamily family = FontFamily.GenericMonospace;
     FontStyle fontStyle = FontStyle.Bold;
     float fontSize = 10;
     if (font != null) {
         family = font.FontFamily;
         fontStyle = font.Style;
         fontSize = font.SizeInPoints;
     }
     GraphicsPath p = new GraphicsPath();
     p.AddString(
         text,
         family,
         (int)fontStyle,
         gr.DpiY * fontSize / 72,
         new Point(x, y),
         new StringFormat());
     if (x < 0 || center) {
         if (x < 0) {
             x = (int)(Math.Abs(x) - p.GetBounds().Width - 10);
         }
         if (center) {
             y = (int)((maxHeight - (p.GetBounds().Height + p.GetBounds().Y)) / 2);
         }
         p = new GraphicsPath();
         p.AddString(
             text,
             family,
             (int)fontStyle,
             gr.DpiY * fontSize / 72,
             new Point(x, y),
             new StringFormat());
     }
     maxHeight = maxHeight < 0 ? (int)p.GetBounds().Height : maxHeight;
     if (fillColor != Color.Empty) {
         using (Brush brush = new SolidBrush(fillColor)) {
             gr.FillRectangle(brush, new RectangleF(p.GetBounds().X - 8, 0, p.GetBounds().Width + 16, maxHeight - 1));
         }
         gr.DrawRectangle(Pens.Black, new Rectangle((int)p.GetBounds().X - 8, 0, (int)p.GetBounds().Width + 16, maxHeight - 1));
     }
     using (Pen pen = new Pen(traceColor, 2)) {
         gr.DrawPath(pen, p);
     }
     using (SolidBrush brush = new SolidBrush(textColor)) {
         gr.FillPath(brush, p);
     }
 }
        public GraphicsQualityManager(Graphics g, bool setHighQuality = true)
        {
            this.g = g;

            previousCompositingQuality = g.CompositingQuality;
            previousInterpolationMode = g.InterpolationMode;
            previousSmoothingMode = g.SmoothingMode;

            if (setHighQuality)
            {
                SetHighQuality();
            }
        }
예제 #10
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;
		}
예제 #11
0
        /// <summary>
        /// Initialize a new instance of the UseAntiAlias class.
        /// </summary>
        /// <param name="graphics">Graphics instance.</param>
        public UseAntiAlias(Graphics graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics",
                    string.Format(CultureInfo.InvariantCulture,
                    Resources.IDS_ArgumentException,
                    "graphics"));
            }

            this.m_graphics = graphics;
            this.m_smoothingMode = m_graphics.SmoothingMode;
            this.m_graphics.SmoothingMode = SmoothingMode.AntiAlias;
        }
예제 #12
0
        /// <summary>
        /// Initialize a new instance of the UseAntiAlias class.
        /// </summary>
        /// <param name="graphics">Graphics instance.</param>
        public UseAntiAlias(Graphics graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics",
                    string.Format(System.Globalization.CultureInfo.InvariantCulture,
                    BSE.Windows.Forms.Properties.Resources.IDS_ArgumentException,
                    "graphics"));
            }

            this.m_graphics = graphics;
            this.m_smoothingMode = m_graphics.SmoothingMode;
            this.m_graphics.SmoothingMode = SmoothingMode.AntiAlias;
        }
예제 #13
0
        public static Image Resize(this Image image, int newWidth, int newHeight, SmoothingMode quality = SmoothingMode.HighQuality)
        {
            var newImage = new Bitmap(newWidth, newHeight);

            using (var graphics = Graphics.FromImage(newImage))
            {
                graphics.SmoothingMode = quality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                graphics.DrawImage(image, new Rectangle(0, 0, newWidth, newHeight));
            }

            return newImage;
        }
	// 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;
			}
예제 #15
0
        public void WatermarkImageWithText(Image inputImage, ref Image outputImage, SmoothingMode smoothingMode,
                                           string text, Font font, int x, int y, bool renderOver, Brush under,
                                           Brush over, StringAlignment xAlignment, StringAlignment yAlignment)
        {
            int phWidth = inputImage.Width;
            int phHeight = inputImage.Height;

            //create a Bitmap the Size of the original photograph
            var bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);

            bmPhoto.SetResolution(inputImage.HorizontalResolution, inputImage.VerticalResolution);

            Graphics grPhoto = null;

            try
            {
                //load the Bitmap into a Graphics object 
                grPhoto = Graphics.FromImage(bmPhoto);

                //Set the rendering quality for this Graphics object
                grPhoto.SmoothingMode = smoothingMode;

                //Draws the photo Image object at original size to the graphics object.
                grPhoto.DrawImage(
                    inputImage, // Photo Image object
                    new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure
                    0, // x-coordinate of the portion of the source image to draw. 
                    0, // y-coordinate of the portion of the source image to draw. 
                    phWidth, // Width of the portion of the source image to draw. 
                    phHeight, // Height of the portion of the source image to draw. 
                    GraphicsUnit.Pixel); // Units of measure

                // calculate the text size
                SizeF textSize = grPhoto.MeasureString(text, font);
                int textX = CalculatePosition(x, phWidth, (int) textSize.Width, xAlignment);
                int textY = CalculatePosition(y, phHeight, (int) textSize.Height, yAlignment);

                if (renderOver) DrawString(grPhoto, text, font, textX + 1, textY + 1, over);
                DrawString(grPhoto, text, font, textX, textY, under);

                outputImage = bmPhoto;
                bmPhoto = null;
            }
            finally
            {
                if (grPhoto != null) grPhoto.Dispose();
                if (bmPhoto != null) bmPhoto.Dispose();
            }
        }
예제 #16
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;
            }
        }
예제 #17
0
 public void 缩放图像Test()
 {
     Image 图像 = null; // TODO: 初始化为适当的值
     int 指定宽度 = 0; // TODO: 初始化为适当的值
     int 指定高度 = 0; // TODO: 初始化为适当的值
     缩放方式 缩放方式 = new 缩放方式(); // TODO: 初始化为适当的值
     InterpolationMode 插值算法 = new InterpolationMode(); // TODO: 初始化为适当的值
     SmoothingMode 平滑模式 = new SmoothingMode(); // TODO: 初始化为适当的值
     CompositingQuality 合成质量 = new CompositingQuality(); // TODO: 初始化为适当的值
     Bitmap expected = null; // TODO: 初始化为适当的值
     Bitmap actual;
     actual = Drawing处理函数.缩放图像(图像, 指定宽度, 指定高度, 缩放方式, 插值算法, 平滑模式, 合成质量);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("验证此测试方法的正确性。");
 }
예제 #18
0
        /// <summary>
        /// Rasterize a circle of specified radius in an image.
        /// </summary>
        /// <param name="radius"></param>
        /// <param name="smoothingMode"></param>
        /// <returns></returns>
        public static Bitmap CreateCircle(int radius, SmoothingMode smoothingMode)
        {
            int size = Math.Max(2 * radius, 1);
            Bitmap image = new Bitmap(size, size, PixelFormat.Format32bppArgb);

            Graphics g = Graphics.FromImage(image);

            g.SmoothingMode = smoothingMode;
            g.FillRectangle(Brushes.Black, 0, 0, size, size);
            g.FillEllipse(Brushes.White, new RectangleF(
                new PointF(-0.5f, -0.5f), new SizeF(size, size)));

            g.Dispose();
            return image;
        }
예제 #19
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;
        }
예제 #20
0
파일: Utils.cs 프로젝트: eakova/resizer
        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;
        }
예제 #21
0
		//Creates a new element by copying an existing element
		//Layer should be assigned by the system and should not be copied
		public Element(Element prototype)
		{
			mKey = string.Empty;
			mLayerKey = string.Empty;

			mBorderColor = prototype.BorderColor;
			mBorderStyle = prototype.BorderStyle;
			mBorderWidth = prototype.BorderWidth;
			mSmoothingMode = prototype.SmoothingMode;
			mCustomPen = prototype.CustomPen;
			mDrawShadow = prototype.DrawShadow;
			mOpacity = prototype.Opacity;
			mTooltip = prototype.Tooltip;
			mVisible = prototype.Visible;
			mCursor = prototype.Cursor;

			mPath = prototype.GetPath();
			mRectF = prototype.Rectangle;
			mContainer = prototype.Container;
			
			mTag = prototype.Tag;
		}
        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;
        }
예제 #23
0
        /// <summary>
        /// Public static method that draw a bitmap / widget centered in a button/rectangle. The bitmap is obtained
        /// from the project resources, it is not passed in.
        /// </summary>
        /// <param name="boundingBox">The bounding area to draw the bitmap / widget in.</param>
        /// <param name="resourceName">The name of the resource prefixed with the namespace of the project
        /// that contains it, you must specify the extension as well i.e. 'SSXPControls.mybitmap.bmp'.</param>
        /// <param name="graphics">The graphics object used to do the drawing passed in from client code.</param>
        public static void DrawButtonWidgetCentered(Rectangle boundingBox, string resourceName, Graphics graphics)
        {
            Assembly assmb = Assembly.GetExecutingAssembly();
            Stream   strm  = assmb.GetManifestResourceStream(resourceName);

            using (Bitmap bmp = new Bitmap(strm))
            {
                bmp.MakeTransparent(Color.FromArgb(255, 255, 255));

                SmoothingMode originalMode = graphics.SmoothingMode;

                graphics.SmoothingMode = SmoothingMode.AntiAlias;

                int x = boundingBox.Left + (boundingBox.Width / 2) - (bmp.Width / 2);
                int y = (boundingBox.Height / 2) - (bmp.Height / 2);

                graphics.DrawImage(bmp, new Rectangle(x, y, bmp.Width, bmp.Height));

                graphics.SmoothingMode = originalMode;
                bmp.Dispose();
            }
            strm.Close();
        }
예제 #24
0
        void DrawGlyphCore(RadialMenuGraphicsInfoArgs e, CustomRadialMenuViewInfo viewInfo)
        {
            Image glyph = GetActualGlyph(e);

            if ((e.ViewInfo.Menu as CustomRadialMenu).ActualBarLinksHolderEx != e.ViewInfo.Menu)
            {
                DrawColoredGlyph(e, (viewInfo.Menu as CustomRadialMenu).BackButtonImage);
            }
            else
            {
                e.Graphics.DrawImage(glyph, viewInfo.CalcGlyphClientBoundsEx(viewInfo.GlyphBounds, glyph));
            }
            SmoothingMode mode = e.Graphics.SmoothingMode;

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            try {
                //e.Graphics.DrawEllipse(e.Cache.GetPen(Color.Red, 2), viewInfo.GlyphBounds);
                DrawGlyphSelection(e);
            }
            finally {
                e.Graphics.SmoothingMode = mode;
            }
        }
예제 #25
0
        /// <summary>
        /// Initialize a new instance of the GraphicsHint class.
        /// </summary>
        /// <param name="graphics">Graphics context.</param>
        /// <param name="hint">Temporary hint mode to apply.</param>
        public GraphicsHint(Graphics graphics, PaletteGraphicsHint hint)
        {
            // Cache graphics instance
            _graphics = graphics;

            // Remember current smoothing mode
            _smoothingMode = _graphics.SmoothingMode;

            // Apply new hint
            switch (hint)
            {
                case PaletteGraphicsHint.None:
                    _graphics.SmoothingMode = SmoothingMode.None;
                    break;
                case PaletteGraphicsHint.AntiAlias:
                    _graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    break;
                default:
                    // Should never happen!
                    Debug.Assert(false);
                    break;
            }
        }
예제 #26
0
        /// <summary>
        /// 创建缩略图
        /// </summary>
        /// <param name="img"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="interpolation"></param>
        /// <param name="smoothing"></param>
        /// <returns></returns>
        public static Bitmap Thumbnail(Image img, int width, int height,
                                       InterpolationMode interpolation = InterpolationMode.High,
                                       SmoothingMode smoothing         = SmoothingMode.HighSpeed)
        {
            int ow = img.Width;
            int oh = img.Height;

            //新建一个bmp图片
            Bitmap bitmap = new Bitmap(width, height);
            //新建一个画板
            Graphics g = Graphics.FromImage(bitmap);

            //设置高质量插值法
            g.InterpolationMode = InterpolationMode.High;
            //设置低质量,高速度呈现平滑程度
            g.SmoothingMode = SmoothingMode.HighSpeed;
            //清空画布并以透明背景色填充
            g.Clear(Color.Transparent);

            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(img, new Rectangle(0, 0, width, height), new Rectangle(0, 0, ow, oh), GraphicsUnit.Pixel);
            return(bitmap);
        }
예제 #27
0
        /// <summary>
        /// Resize the image to the specified width and height.
        /// </summary>
        /// <param name="image">The image to resize.</param>
        /// <param name="width">The width to resize to.</param>
        /// <param name="height">The height to resize to.</param>
        /// <returns>The resized image.</returns>
        public static System.Drawing.Bitmap Resize(this System.Drawing.Image image, int width, int height,
            InterpolationMode interpolationMode = InterpolationMode.HighQualityBicubic,
            SmoothingMode smoothingMode = SmoothingMode.HighQuality)
        {
            //a holder for the result
            Bitmap result = new Bitmap(width, height);
            // set the resolutions the same to avoid cropping due to resolution differences
            result.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            //use a graphics object to draw the resized image into the bitmap
            using (Graphics graphics = Graphics.FromImage(result))
            {
                //set the resize quality modes to high quality
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode = interpolationMode;
                graphics.SmoothingMode = smoothingMode;
                //draw the image into the target bitmap
                graphics.DrawImage(image, 0, 0, result.Width, result.Height);
            }

            //return the resulting bitmap
            return result;
        }
예제 #28
0
        public static Image ReDraw(this Image main, int w, int h,
                                   CompositingQuality quality   = CompositingQuality.Default, //linear?
                                   SmoothingMode smoothing_mode = SmoothingMode.None,
                                   InterpolationMode ip_mode    = InterpolationMode.NearestNeighbor)
        {
            //size
            double dbl = (double)main.Width / (double)main.Height;

            //preserve size ratio
            if ((int)((double)h * dbl) <= w)
            {
                w = (int)((double)h * dbl);
            }
            else
            {
                h = (int)((double)w / dbl);
            }

            //draw
            Image newImage = new System.Drawing.Bitmap(w, h);

            using (Graphics gfx = Graphics.FromImage(newImage))
            {
                gfx.CompositingQuality = quality;
                gfx.SmoothingMode      = smoothing_mode;
                gfx.InterpolationMode  = ip_mode;
                gfx.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                gfx.Clear(Color.Transparent);

                gfx.DrawImage(main,
                              new System.Drawing.Rectangle(0, 0, w, h),
                              new System.Drawing.Rectangle(0, 0, main.Width, main.Height),
                              System.Drawing.GraphicsUnit.Pixel);
            }

            return(newImage);
        }
예제 #29
0
        /// <summary>
        /// Paints the polyline.
        /// </summary>
        /// <param name="g">Graphic context</param>
        /// <param name="p">Pen to use</param>
        protected override void PaintPolyline(Graphics g, Pen p)
        {
            if (From == null)
            {
                return;
            }
            if (To == null || ((this.Points.Count - 4) % 3 != 0))
            {
                base.PaintPolyline(g, p);
                return;
            }

            // Get end points
            PointF s = From.Shape.ConnectionPoint(From);
            PointF e = To.Shape.ConnectionPoint(To);

            // Iterate the list of polyline points and paint the lines between them
            SmoothingMode m = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.HighQuality;

            PointF[] points = new PointF[this.Points.Count];
            this.Points.CopyTo(points, 0);
            points[0] = s;
            points[points.Length - 1] = e;

            g.DrawBeziers(p, points);
            g.SmoothingMode = m;

            // draw label
            if (label != null && this.label.Length != 0)
            {
                PointF     middle     = (PointF)this.Points[this.Points.Count / 2];
                SolidBrush labelBrush = new SolidBrush(this.LabelColor);
                g.DrawString(this.label, this.labelFont, labelBrush, middle);
            }
        }
        // http://forums.asp.net/p/942160/1128861.aspx
        private static void FillRoundedRectangle(Graphics grPhoto, Rectangle r, int d, Brush b)
        {
            Graphics graphics = grPhoto;
            int      tempInt  = d / 2;

            // Create points that define polygon.
            Point[] points =
            {
                new Point(tempInt,                            1),
                new Point(r.Width - tempInt,                  1),
                new Point(r.Width,           tempInt),
                new Point(r.Width,           r.Height - tempInt),
                new Point(r.Width - tempInt, r.Height),
                new Point(tempInt,           r.Height),
                new Point(1,                 r.Height - tempInt),
                new Point(1,                 tempInt)
            };

            // Define fill mode.
            const FillMode newFillMode = FillMode.Winding;

            graphics.SmoothingMode = SmoothingMode.Default;
            graphics.FillPolygon(b, points, newFillMode);

            // anti alias distorts fill so remove it.
            SmoothingMode mode = grPhoto.SmoothingMode;

            grPhoto.SmoothingMode = SmoothingMode.HighQuality;
            grPhoto.FillPie(b, r.X, r.Y, d, d, 180, 90);
            grPhoto.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90);
            grPhoto.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90);
            grPhoto.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
            grPhoto.FillRectangle(b, r.X + d / 2, r.Y, r.Width - d, d / 2);
            grPhoto.FillRectangle(b, r.X, r.Y + d / 2, r.Width, r.Height - d);
            grPhoto.FillRectangle(b, r.X + d / 2, r.Y + r.Height - d / 2, r.Width - d, d / 2);
            grPhoto.SmoothingMode = mode;
        }
            // ===================================================================

            protected override void OnPaint(PaintEventArgs e)
            {
                Graphics g = e.Graphics;// CreateGraphics();

                SmoothingMode prevSmoothingMode = g.SmoothingMode;

                g.SmoothingMode = (m_bHighQuality ? SmoothingMode.HighQuality
                                                  : SmoothingMode.Default);

                /* Reset our offset so we don't continually shift to the right: */

                m_OffsetX = 0;

                if (m_bShowMinMax)
                {
                    DrawLabels(ref g);
                }

                if (m_bShowGrid)
                {
                    DrawGrid(ref g);
                }

                if (m_OffsetX != 0)
                {
                    /* This is to avoid crossing the left grid boundary when
                     * working with lines with great thickness */

                    g.Clip = new Region(
                        new Rectangle(m_OffsetX, 0, Width - m_OffsetX, Height));
                }

                DrawLines(ref g);
                g.ResetClip();

                g.SmoothingMode = prevSmoothingMode;
            }
예제 #32
0
        /// <summary>
        /// Draw a tic mark at the specified single position.  This includes the inner, outer,
        /// cross and opposite tic marks as required.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="pen">Graphic <see cref="Pen"/> with which to draw the tic mark.</param>
        /// <param name="pixVal">The pixel location of the tic mark on this
        /// <see cref="Axis"/></param>
        /// <param name="topPix">The pixel value of the top of the axis border</param>
        /// <param name="shift">The number of pixels to shift this axis, based on the
        /// value of <see cref="Axis.Cross"/>.  A positive value is into the ChartRect relative to
        /// the default axis position.</param>
        /// <param name="scaledTic">The scaled size of a minor tic, in pixel units</param>
        internal void Draw(Graphics g, GraphPane pane, Pen pen, float pixVal, float topPix,
                           float shift, float scaledTic)
        {
            // draw the outside tic
            SmoothingMode smode = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.None;
            if (this.IsOutside)
            {
                g.DrawLine(pen, pixVal, shift, pixVal, shift + scaledTic);
            }

            // draw the cross tic
            if (_isCrossOutside)
            {
                g.DrawLine(pen, pixVal, 0.0f, pixVal, scaledTic);
            }

            // draw the inside tic
            if (this.IsInside)
            {
                g.DrawLine(pen, pixVal, shift, pixVal, shift - scaledTic);
            }

            // draw the inside cross tic
            if (_isCrossInside)
            {
                g.DrawLine(pen, pixVal, 0.0f, pixVal, -scaledTic);
            }

            // draw the opposite tic
            if (this.IsOpposite)
            {
                g.DrawLine(pen, pixVal, topPix, pixVal, topPix + scaledTic);
            }
            g.SmoothingMode = smode;
        }
예제 #33
0
        public void DrawGlyph(Graphics g)
        {
            if (isMouseOver)
            {
                Color fill = renderer.ColorTable.ButtonSelectedHighlight; //Color.FromArgb(35, SystemColors.Highlight);
                g.FillRectangle(new SolidBrush(fill), glyphRect);
                Rectangle borderRect = glyphRect;

                borderRect.Width--;
                borderRect.Height--;

                g.DrawRectangle(SystemPens.Highlight, borderRect);
            }

            SmoothingMode bak = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.Default;

            using (var pen = new Pen(Color.Black))
            {
                pen.Width = 2;

                g.DrawLine(pen, new Point(glyphRect.Left + (glyphRect.Width / 3) - 2, glyphRect.Height / 2 - 1),
                           new Point(glyphRect.Right - (glyphRect.Width / 3), glyphRect.Height / 2 - 1));
            }

            g.FillPolygon(Brushes.Black, new[]
            {
                new Point(glyphRect.Left + (glyphRect.Width / 3) - 2,
                          glyphRect.Height / 2 + 2),
                new Point(glyphRect.Right - (glyphRect.Width / 3), glyphRect.Height / 2 + 2)
                ,
                new Point(glyphRect.Left + glyphRect.Width / 2 - 1, glyphRect.Bottom - 4)
            });

            g.SmoothingMode = bak;
        }
예제 #34
0
        private void DrawSegmentGrid(FRPaintEventArgs e, float offsetX, float offsetY)
        {
            Graphics      g             = e.Graphics;
            SmoothingMode saveSmoothing = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Brush b = e.Cache.GetBrush(Border.Color);

            int[] grid      = new int[] { 111111, 110001, 101001, 100101, 100011, 111111, 110001, 101001, 100101, 100011, 111111 };
            float ratioX    = FSegmentWidth / (Units.Centimeters * 0.5f);
            float ratioY    = FSegmentHeight / (Units.Centimeters * 1);
            float pointSize = Units.Millimeters * 0.25f;
            float y         = AbsTop;

            foreach (int gridRow in grid)
            {
                int   row = gridRow;
                float x   = AbsLeft;

                while (row > 0)
                {
                    if (row % 10 == 1)
                    {
                        g.FillEllipse(b, (x + offsetX - pointSize / 2) * e.ScaleX, (y + offsetY - pointSize / 2) * e.ScaleY,
                                      pointSize * e.ScaleX, pointSize * e.ScaleY);
                    }
                    row /= 10;

                    x += Units.Millimeters * 1 * ratioX;
                }

                y += Units.Millimeters * 1 * ratioY;
            }

            g.SmoothingMode = saveSmoothing;
        }
예제 #35
0
        /// <summary>
        /// Draw a checkmark.
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        /// <param name="color">Color for the checkmark.</param>
        /// <param name="item">Checked menu item.</param>
        private void DrawCheck(Graphics g, Color color, FlatMenuItem item)
        {
            const int size = 11;

            int x = item.ClientRectangle.X - FlatPopupMenu.checkAreaWidth - 3;
            int y = item.ClientRectangle.Y + item.ClientRectangle.Height / 2 - size / 2;

            Rectangle r = new Rectangle(x, y, size, size);

            this.DrawBackground(g, r, this.BackColor);

            using (Pen pen = new Pen(color, 0))
            {
                g.DrawRectangle(pen, r);
                if (item.Checked)
                {
                    SmoothingMode oldMode = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.DrawLine(pen, x + 2, y + 7, x + 4, y + 9);
                    g.DrawLine(pen, x + 4, y + 9, x + 9, y + 4);
                    g.SmoothingMode = oldMode;
                }
            }
        }
예제 #36
0
        public void DrawTabItem(Graphics g, Rectangle bounds, TabItemState state)
        {
            SmoothingMode _Old = SmoothingMode.None;
            bool          _ModifiedSmoothMode = false;

            if (g.SmoothingMode != SmoothingMode.AntiAlias && g.SmoothingMode != SmoothingMode.HighQuality)
            {
                _Old                = g.SmoothingMode;
                g.SmoothingMode     = SmoothingMode.AntiAlias;
                _ModifiedSmoothMode = true;
            }
            bounds = GetModifiedBounds(bounds);

            if (state == TabItemState.Selected)
            {
                GraphicsPath path = new GraphicsPath();
                path.AddLine(new Point(bounds.X, bounds.Height + bounds.Y), new Point(bounds.X, bounds.Y));
                path.AddLine(new Point(bounds.X, bounds.Y), new Point(bounds.Width + bounds.X, bounds.Y));
                path.AddLine(new Point(bounds.Width + bounds.X, bounds.Y), new Point(bounds.X + bounds.Width, bounds.Height + bounds.Y));

                g.FillPath(SystemBrushes.ControlLightLight, path);
                g.DrawPath(SystemPens.ControlDark, path);
            }
            else if (state == TabItemState.Normal)
            {
                g.DrawLine(SystemPens.ControlDark, new Point(bounds.X + bounds.Width, bounds.Y + 4), new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height - 3));
                g.DrawLine(SystemPens.ControlDark, new Point(bounds.X, bounds.Y + bounds.Height), new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height));
            }
            g.DrawLine(SystemPens.ControlLightLight, new Point(bounds.X, bounds.Y + bounds.Height + 1), new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height + 1));


            if (_ModifiedSmoothMode)
            {
                g.SmoothingMode = _Old;
            }
        }
예제 #37
0
        /// <summary>
        /// Draw the <see cref="Symbol"/> to the specified <see cref="Graphics"/> device
        /// at the specified location.  This routine draws a single symbol.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="x">The x position of the center of the symbol in
        /// pixel units</param>
        /// <param name="y">The y position of the center of the symbol in
        /// pixel units</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        /// <param name="isSelected">Indicates that the <see cref="Symbol" /> should be drawn
        /// with attributes from the <see cref="Selection" /> class.
        /// </param>
        public void DrawSymbol(Graphics g, GraphPane pane, int x, int y,
                               float scaleFactor, bool isSelected, PointPair dataValue)
        {
            Symbol source = this;

            if (isSelected)
            {
                source = Selection.Symbol;
            }

            // Only draw if the symbol is visible
            if (_isVisible &&
                this.Type != SymbolType.None &&
                x < 100000 && x > -100000 &&
                y < 100000 && y > -100000)
            {
                SmoothingMode sModeSave = g.SmoothingMode;
                if (_isAntiAlias)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                }

                using (Pen pen = _border.GetPen(pane, scaleFactor, dataValue))
                {
                    using (GraphicsPath path = this.MakePath(g, scaleFactor))
                    {
                        using (Brush brush = this.Fill.MakeBrush(path.GetBounds(), dataValue))
                        {
                            DrawSymbol(g, x, y, path, pen, brush);
                        }
                    }
                }

                g.SmoothingMode = sModeSave;
            }
        }
예제 #38
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            Color color     = HyacinthPalette.BackColor.Form(HyacinthThemeStyle.Default);
            Color foreColor = HyacinthPalette.ForeColor.Form(HyacinthThemeStyle.Default);

            e.Graphics.Clear(color);
            using (SolidBrush styleBrush = HyacinthPalette.GetStyleBrush(HyacinthColorStyle.Black))
            {
                Rectangle rect = new Rectangle(0, 0, this.Width, 5);
                e.Graphics.FillRectangle((Brush)styleBrush, rect);
            }
            if (this.BorderStyle != HyacinthBorderStyle.None)
            {
                using (Pen pen = new Pen(HyacinthPalette.BorderColor.Form(HyacinthThemeStyle.Default)))
                    e.Graphics.DrawLines(pen, new Point[4]
                    {
                        new Point(0, 5),
                        new Point(0, this.Height - 1),
                        new Point(this.Width - 1, this.Height - 1),
                        new Point(this.Width - 1, 5)
                    });
            }
            //if (!this.displayHeader)
            //    return;
            //TextRenderingHint textRenderingHint = e.Graphics.TextRenderingHint;
            //e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            SmoothingMode smoothingMode = e.Graphics.SmoothingMode;

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            //Rectangle bounds = new Rectangle(20, 20, this.ClientRectangle.Width - 40, 40);
            //TextFormatFlags flags = TextFormatFlags.EndEllipsis | this.GetTextFormatFlags();
            //TextRenderer.DrawText((IDeviceContext)e.Graphics, this.Text, MetroFonts.Title, bounds, foreColor, flags);
            //e.Graphics.TextRenderingHint = textRenderingHint;
            e.Graphics.SmoothingMode = smoothingMode;
        }
예제 #39
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle imageBounds = Rectangle.Empty;

            imageBounds.Size = _increaseSize ? _maxSize.Size : _minSize.Size;

            Image img = _increaseSize ? Properties.Resources.GreenCircle_27x27 : Properties.Resources.TanCircle_27x27;

            imageBounds.Location = new Point(
                (ClientRectangle.Width - imageBounds.Width) / 2,
                (ClientRectangle.Height - imageBounds.Height) / 2);

            CompositingQuality compositingQuality = e.Graphics.CompositingQuality;
            InterpolationMode  interpolationMode  = e.Graphics.InterpolationMode;
            SmoothingMode      smoothingMode      = e.Graphics.SmoothingMode;

            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode      = SmoothingMode.HighQuality;
            e.Graphics.DrawImage(img, imageBounds);
            e.Graphics.CompositingQuality = compositingQuality;
            e.Graphics.InterpolationMode  = interpolationMode;
            e.Graphics.SmoothingMode      = smoothingMode;
        }
예제 #40
0
        //Implement a base rendering of an element selection
        public override void RenderSelection(IRenderable renderable, Graphics graphics, ControlRender render)
        {
            TreeLine line = renderable as TreeLine;

            if (line.Handles == null)
            {
                return;
            }

            SmoothingMode smoothing = graphics.SmoothingMode;

            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            Handle     previousHandle = null;
            SolidBrush brushWhite     = new SolidBrush(Color.White);
            Pen        pen            = Singleton.Instance.SelectionStartPen;
            SolidBrush brush          = Singleton.Instance.SelectionStartBrush;

            foreach (Handle handle in line.Handles)
            {
                if (previousHandle != null)
                {
                    graphics.FillPath(brushWhite, previousHandle.Path);
                    graphics.FillPath(brush, previousHandle.Path);
                    graphics.DrawPath(pen, previousHandle.Path);
                    pen   = Singleton.Instance.SelectionPen;   //Set to normal brush
                    brush = Singleton.Instance.SelectionBrush; //Set to normal pen
                }
                previousHandle = handle;
            }
            graphics.FillPath(brushWhite, previousHandle.Path);
            graphics.FillPath(Singleton.Instance.SelectionEndBrush, previousHandle.Path);
            graphics.DrawPath(Singleton.Instance.SelectionEndPen, previousHandle.Path);

            graphics.SmoothingMode = smoothing;
        }
예제 #41
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            Rectangle backgroundRect  = this.ClientRectangle;
            Color     backgroundColor = this.BackgroundColor;
            Color     lineColor       = FieldFocused == true ? this.AccentColor : this.TextColor;
            int       lineSize        = borderSize;
            int       lineOffset      = lineSize / 2;

            if (this.Enabled == false)
            {
                lineColor = disabledTextColor;
            }

            SmoothingMode lastSmoothingMode = pevent.Graphics.SmoothingMode;

            pevent.Graphics.SmoothingMode = SmoothingMode.None;

            using (SolidBrush brush = new SolidBrush(backgroundColor))
            {
                pevent.Graphics.FillRectangle(brush, pevent.ClipRectangle);
            }

            using (Pen pen = new Pen(lineColor, lineSize))
            {
                pen.Alignment = PenAlignment.Left;

                pevent.Graphics.DrawLine(
                    pen,
                    backgroundRect.Left,
                    backgroundRect.Bottom - lineOffset,
                    backgroundRect.Right,
                    backgroundRect.Bottom - lineOffset);
            }

            pevent.Graphics.SmoothingMode = lastSmoothingMode;
        }
예제 #42
0
    public void toggleSmoothingMode()
    {
        if (smoothingMode == SmoothingMode.Lerp)
        {
            smoothingMode = SmoothingMode.ExponentialSmoothing;
        }
        else if (smoothingMode == SmoothingMode.ExponentialSmoothing)
        {
            smoothingMode = SmoothingMode.Lerp;
        }

        VectorInterpolation[] all = GetComponentsInChildren <VectorInterpolation> ();
        foreach (VectorInterpolation a in all)
        {
            a.ResetAll();
        }
        Debug.Log(transform.name + ": Toggled to " + smoothingMode);

        KalmanMultiple[] kalmans = GetComponentsInChildren <KalmanMultiple> ();
        foreach (KalmanMultiple kalman in kalmans)
        {
            kalman.Reset();
        }
    }
예제 #43
0
        public override void Draw(Graphics Graphics, StatusElementResources Resources)
        {
            SmoothingMode PrevSmoothingMode = Graphics.SmoothingMode;

            Graphics.SmoothingMode = SmoothingMode.HighQuality;

            using (GraphicsPath Path = new GraphicsPath())
            {
                Path.StartFigure();
                Path.AddLine(Bounds.Left + (MergeLeft? 1 : 0), Bounds.Top, Bounds.Left - (MergeLeft? 1 : 0), Bounds.Bottom);
                Path.AddLine(Bounds.Left - (MergeLeft? 1 : 0), Bounds.Bottom, Bounds.Right - 2 - (MergeRight? 1 : 0), Bounds.Bottom);
                Path.AddLine(Bounds.Right - 2 - (MergeRight? 1 : 0), Bounds.Bottom, Bounds.Right - 2 + (MergeRight? 1 : 0), Bounds.Top);
                Path.AddLine(Bounds.Right - 2 + (MergeRight? 1 : 0), Bounds.Top, Bounds.Left + (MergeLeft? 1 : 0), Bounds.Top);
                Path.CloseFigure();

                using (SolidBrush Brush = new SolidBrush(bMouseOver? HoverBackgroundColor : BackgroundColor))
                {
                    Graphics.FillPath(Brush, Path);
                }
            }

            Graphics.SmoothingMode = PrevSmoothingMode;
            TextRenderer.DrawText(Graphics, Name, Resources.BadgeFont, Bounds, Color.White, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix | TextFormatFlags.PreserveGraphicsClipping);
        }
예제 #44
0
        protected void DrawCustomBorder(ControlGraphicsInfoArgs info)
        {
            SmoothingMode smoothing = info.Graphics.SmoothingMode;

            try {
                info.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                using (GraphicsPath path = new GraphicsPath()) {
                    int       halfWidth = -(int)Math.Ceiling(highlightPen.Width / 2.0) - InnerIndent;
                    Rectangle bounds    = Rectangle.Inflate(info.Bounds, halfWidth, halfWidth);
                    int       fraction  = 6;
                    int       right     = bounds.Right - fraction - 1;
                    int       bottom    = bounds.Bottom - fraction - 1;
                    path.AddArc(bounds.X, bounds.Y, fraction, fraction, 180, 90);
                    path.AddArc(right, bounds.Y, fraction, fraction, 270, 90);
                    path.AddArc(right, bottom, fraction, fraction, 0, 90);
                    path.AddArc(bounds.Left, bottom, fraction, fraction, 90, 90);
                    path.CloseFigure();
                    info.Graphics.DrawPath(highlightPen, path);
                }
            }
            finally {
                info.Graphics.SmoothingMode = smoothing;
            }
        }
예제 #45
0
            /// <summary>
            /// Draws a rectangle with rounded edges.
            /// </summary>
            /// <param name="g">The System.Drawing.Graphics object to be used to draw the rectangle.</param>
            /// <param name="p">A System.Drawing.Pen object that determines the color, width, and style of the rectangle.</param>
            /// <param name="rc">A System.Drawing.Rectangle structure that represents the rectangle to draw.</param>
            /// <param name="size">Pixel indentation that determines the roundness of the corners.</param>
            public static void DrawRoundedRectangle(Graphics g, Pen p, Rectangle rc, Size size)
            {
                // 1 pixel indent in all sides = Size(4, 4)
                // To make pixel indentation larger, change by a factor of 4,
                // i. e., 2 pixels indent = Size(8, 8);

                SmoothingMode oldSmoothingMode = g.SmoothingMode;

                g.SmoothingMode = SmoothingMode.AntiAlias;

                g.DrawLine(p, rc.Left + size.Width / 2, rc.Top, rc.Right - size.Width / 2, rc.Top);
                g.DrawArc(p, rc.Right - size.Width, rc.Top, size.Width, size.Height, 270, 90);

                g.DrawLine(p, rc.Right, rc.Top + size.Height / 2, rc.Right, rc.Bottom - size.Height / 2);
                g.DrawArc(p, rc.Right - size.Width, rc.Bottom - size.Height, size.Width, size.Height, 0, 90);

                g.DrawLine(p, rc.Right - size.Width / 2, rc.Bottom, rc.Left + size.Width / 2, rc.Bottom);
                g.DrawArc(p, rc.Left, rc.Bottom - size.Height, size.Width, size.Height, 90, 90);

                g.DrawLine(p, rc.Left, rc.Bottom - size.Height / 2, rc.Left, rc.Top + size.Height / 2);
                g.DrawArc(p, rc.Left, rc.Top, size.Width, size.Height, 180, 90);

                g.SmoothingMode = oldSmoothingMode;
            }
예제 #46
0
 private static Bitmap CreateOneUnitToOnePixelBitmap(
     DxfModel model,
     Matrix4D transform,
     GraphicsConfig graphicsConfig,
     SmoothingMode smoothingMode)
 {
     // first calculate the size of the model
     //BoundsCalculator boundsCalculator = new BoundsCalculator(graphicsConfig);
     //boundsCalculator.GetBounds(model, transform);
     //Bounds3D bounds = boundsCalculator.Bounds;
     //Vector3D delta = bounds.Delta;
     //// now determine image size from this
     //// Note: Have to add 2 extra pixels on each side, otherwise Windows will not render
     //// the graphics on the outer edges. Also there seems to be always an empty unused line
     //// around the bitmap, but that's not a problem, just a minor waste of space.
     //const int margin = 2;
     //int width = (int)System.Math.Ceiling(delta.X) + 2 * margin;
     //int height = (int)System.Math.Ceiling(delta.Y) + 2 * margin;
     //// Now move the model so it is centered in the coordinate ranges
     //// margin &lt;= x &lt;= width+margin and margin &lt;= y &lt;= height+margin
     //// Be careful: in DXF y points up, but in Bitmap it points down!
     //Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
     //  bounds.Corner1,
     //  bounds.Corner2,
     //  new Point3D(bounds.Corner1.X, bounds.Corner2.Y, 0d),
     //  new Point3D(0d, delta.Y, 0d),
     //  new Point3D(delta.X, 0d, 0d),
     //  new Point3D(margin, margin, 0d)
     //) * transform;
     // now use standard method to create bitmap
     System.Drawing.Size maxSize = new System.Drawing.Size(1000, 600);
     return(ImageExporter.CreateAutoSizedBitmap(model, Matrix4D.Identity,
                                                GraphicsConfig.WhiteBackgroundCorrectForBackColor,
                                                SmoothingMode.HighQuality,
                                                maxSize));
 }
예제 #47
0
        /// <summary>
        /// Affiche l'objet
        /// </summary>
        /// <param name="g"></param>
        /// <param name="maintenant"></param>
        /// <param name="tailleEcran"></param>
        /// <param name="couleur"></param>
        ///
#if USE_GDI_PLUS_FOR_2D
        public override void AfficheGDI(Graphics g, Temps maintenant, Rectangle tailleEcran, Color couleur)
        {
#if TRACER
            RenderStart(CHRONO_TYPE.RENDER);
#endif
            // Mise a jour de la palette de couleurs
            updatePalette(couleur);

            // Construire la bitmap
            updateFrame();
            SmoothingMode      q = g.SmoothingMode;
            CompositingQuality c = g.CompositingQuality;
            InterpolationMode  m = g.InterpolationMode;
            g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            g.CompositingQuality = CompositingQuality.HighSpeed;
            g.InterpolationMode  = InterpolationMode.NearestNeighbor;
            g.DrawImage(_bmp, 0, 0, tailleEcran.Width, tailleEcran.Height);
            g.SmoothingMode      = q;
            g.CompositingQuality = c;
            g.InterpolationMode  = m;
#if TRACER
            RenderStop(CHRONO_TYPE.RENDER);
#endif
        }
예제 #48
0
        public static Bitmap CreateAutoSizedBitmap(
            DxfModel model,
            DxfLayout layout,
            ICollection <DxfViewport> viewports,
            Matrix4D transform,
            GraphicsConfig graphicsConfig,
            SmoothingMode smoothingMode)
        {
            BoundsCalculator boundsCalculator = new BoundsCalculator(graphicsConfig);

            boundsCalculator.GetBounds(model, layout, viewports, transform);
            Bounds3D bounds = boundsCalculator.Bounds;

            if (!bounds.Initialized)
            {
                return(ImageExporter.CreateEmptyBitmap((System.Drawing.Color)graphicsConfig.BackColor, 1, 1));
            }
            WW.Math.Vector3D delta      = bounds.Delta;
            Matrix4D         transform1 = DxfUtil.GetScaleTransform(bounds.Min, bounds.Max, new WW.Math.Point3D(2.0, delta.Y + 2.0, 0.0), new WW.Math.Point3D(delta.X + 2.0, 2.0, 0.0)) * transform;
            int width  = (int)System.Math.Ceiling(delta.X) + 4;
            int height = (int)System.Math.Ceiling(delta.Y) + 4;

            return(ImageExporter.CreateBitmap(model, layout, viewports, transform1, graphicsConfig, smoothingMode, width, height));
        }
예제 #49
0
        /// <summary>
        ///Drawing names.
        ///  <remarks>
        /// Algorithm uses the base class.
        ///  </remarks>
        /// </summary>
        public void RenderTitle(Image image, BoundingRectangle viewBox)
        {
            _titleBuffer.Clear();
            _titleBuffer.AddRange(_allTitleInfo);
            _titleCount = _titleBuffer.Count;
            double scaleFactor = Math.Min(image.Width / viewBox.Width, image.Height / viewBox.Height);

            using (Graphics g = Graphics.FromImage(image))
            {
                SmoothingMode oldSmoothingMode = g.SmoothingMode;

                if (_renderingSettings.AntiAliasText)
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                }
                else
                {
                    g.SmoothingMode = SmoothingMode.HighSpeed;
                }
                base.FlushTitles(g, viewBox, scaleFactor);

                g.SmoothingMode = oldSmoothingMode;
            }
        }
        /// <summary>
        /// Draw the <see cref="Symbol"/> to the specified <see cref="Graphics"/> device
        /// at the specified location.  This routine draws a single symbol.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="x">The x position of the center of the symbol in
        /// pixel units</param>
        /// <param name="y">The y position of the center of the symbol in
        /// pixel units</param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This
        /// scaling factor is calculated by the <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor
        /// represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="dataValue">The data value to be used for a value-based
        /// color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.</param>
        public void DrawSymbol(Graphics g, GraphPane pane, float x, float y,
                               float scaleFactor, IPointPair dataValue)
        {
            // Only draw if the symbol is visible
            if (_isVisible &&
                this.Type != SymbolType.None &&
                x < 100000 && x > -100000 &&
                y < 100000 && y > -100000)
            {
                SmoothingMode sModeSave = g.SmoothingMode;
                if (_isAntiAlias)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                }

                Pen          pen   = _border.MakePen(pane.IsPenWidthScaled, scaleFactor);
                GraphicsPath path  = this.MakePath(g, scaleFactor, false, 1);
                Brush        brush = this.Fill.MakeBrush(path.GetBounds(), dataValue);

                DrawSymbol(g, x, y, path, pen, brush);

                g.SmoothingMode = sModeSave;
            }
        }
예제 #51
0
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            GraphicsPath path       = CreateRoundCornerPath(cellBounds);
            Rectangle    insideRect = new Rectangle(cellBounds.Left + 1, cellBounds.Top + 1, cellBounds.Width - 2, cellBounds.Height - 2);
            GraphicsPath insidePath = CreateRoundCornerPath(insideRect);

            using (SolidBrush b = new SolidBrush(cellStyle.BackColor))
            {
                graphics.FillRectangle(b, cellBounds);
            }

            SmoothingMode lastMode = graphics.SmoothingMode;

            graphics.SmoothingMode = SmoothingMode.HighQuality;

            using (LinearGradientBrush lgb = new LinearGradientBrush(cellBounds,
                                                                     CalendarColors.HeaderCellBackColorLight, CalendarColors.HeaderCellBackColorDark, LinearGradientMode.ForwardDiagonal))
            {
                graphics.FillPath(lgb, path);
            }

            if ((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None)
            {
                using (Pen p = new Pen(CalendarColors.HeaderCellInnerBorderColor))
                {
                    graphics.DrawPath(p, insidePath);
                }

                using (Pen p = new Pen(CalendarColors.HeaderCellBorderColor))
                {
                    graphics.DrawPath(p, path);
                }
            }

            graphics.SmoothingMode = lastMode;
        }
예제 #52
0
        /// <summary>
        ///     Paints the tab page border.
        /// </summary>
        /// <param name="e">
        ///     The <see cref="PaintEventArgs" /> instance containing the event
        ///     data.
        /// </param>
        protected override void PaintTabPageBorder(PaintEventArgs e)
        {
            if (TabCount <= 0)
            {
                return;
            }

            int x1 = SelectedTab.Left - 1;
            var y1 = 0;
            int x2 = SelectedTab.Width + SelectedTab.Left;
            int y2 = SelectedTab.Height + SelectedTab.Top;

            SmoothingMode savedSmoothing = e.Graphics.SmoothingMode;

            e.Graphics.SmoothingMode = SmoothingMode.None;
            using (var p = new Pen(TabBorderColor, -1f))
            {
                e.Graphics.DrawLine(p, x1, y1, x1, y2);
                e.Graphics.DrawLine(p, x1, y2, x2, y2);
                e.Graphics.DrawLine(p, x2, y1, x2, y2);
            }

            e.Graphics.SmoothingMode = savedSmoothing;
        }
예제 #53
0
        /// <summary>
        /// Do all rendering associated with this <see cref="PieItem"/> item to the specified
        /// <see cref="Graphics"/> device.  This method is normally only
        /// called by the Draw method of the parent <see cref="ZedGraph.CurveList"/>
        /// collection object.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="pos">Not used for rendering Pies</param>param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        override public void Draw(Graphics g, GraphPane pane, int pos, float scaleFactor)
        {
            if (pane.Chart._rect.Width <= 0 && pane.Chart._rect.Height <= 0)
            {
                //pane.PieRect = RectangleF.Empty;
                _slicePath = null;
            }
            else
            {
                //pane.PieRect = CalcPieRect( g, pane, scaleFactor, pane.ChartRect );
                CalcPieRect(g, pane, scaleFactor, pane.Chart._rect);

                _slicePath = new GraphicsPath();

                if (!_isVisible)
                {
                    return;
                }

                RectangleF tRect = _boundingRectangle;

                if (tRect.Width >= 1 && tRect.Height >= 1)
                {
                    SmoothingMode sMode = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;

                    Fill   tFill   = _fill;
                    Border tBorder = _border;
                    if (this.IsSelected)
                    {
                        tFill   = Selection.Fill;
                        tBorder = Selection.Border;
                    }

                    using (Brush brush = tFill.MakeBrush(_boundingRectangle))
                    {
                        g.FillPie(brush, tRect.X, tRect.Y, tRect.Width, tRect.Height, this.StartAngle, this.SweepAngle);

                        //add GraphicsPath for hit testing
                        _slicePath.AddPie(tRect.X, tRect.Y, tRect.Width, tRect.Height,
                                          this.StartAngle, this.SweepAngle);

                        if (this.Border.IsVisible)
                        {
                            using (Pen borderPen = tBorder.GetPen(pane, scaleFactor))
                            {
                                g.DrawPie(borderPen, tRect.X, tRect.Y, tRect.Width, tRect.Height,
                                          this.StartAngle, this.SweepAngle);
                            }
                        }

                        if (_labelType != PieLabelType.None)
                        {
                            DrawLabel(g, pane, tRect, scaleFactor);
                        }

                        //brush.Dispose();
                    }

                    g.SmoothingMode = sMode;
                }
            }
        }
예제 #54
0
 /// <summary>
 /// Initialize a new instance of the UseAntiAlias class.
 /// </summary>
 /// <param name="g">Graphics instance.</param>
 public UseAntiAlias(Graphics g)
 {
     _g = g;
     _old = _g.SmoothingMode;
     _g.SmoothingMode = SmoothingMode.AntiAlias;
 }
예제 #55
0
 /// <summary>
 /// Initialize a new instance of the AntiAliasNone class.
 /// </summary>
 /// <param name="g">Graphics instance.</param>
 public AntiAliasNone(Graphics g)
 {
     _g               = g;
     _old             = _g.SmoothingMode;
     _g.SmoothingMode = SmoothingMode.None;
 }
		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);
		}
예제 #57
0
파일: Chart.cs 프로젝트: heber/FreeOQ
		public void DrawSeries(DoubleSeries series, int padNumber, Color color, SimpleDSStyle style, EIndexOption option, SmoothingMode smoothingMode)
		{
			lock(this.dataLock)
			{
				if (!this.volumePadShown && padNumber > 1)
					--padNumber;
				DSView view = new DSView(this.pads[padNumber], series, color, option, smoothingMode);
				view.Style = style;
				this.pads[padNumber].AddPrimitive(view);
				view.SetInterval(this.leftDateTime, this.rightDateTime);
				this.contentUpdated = true;
			}
		}
예제 #58
0
파일: Chart.cs 프로젝트: heber/FreeOQ
		public void DrawSeries(DoubleSeries series, int padNumber, Color color, SimpleDSStyle style, SmoothingMode smoothingMode)
		{
			this.DrawSeries(series, padNumber, color, style, EIndexOption.Null, smoothingMode);
		}
예제 #59
0
파일: Chart.cs 프로젝트: heber/FreeOQ
		public Chart() : base()
		{
			this.PRRwtLFpd5 = -1;
			this.etYww3BBO8 = -1;
			this.doubleSeriesSmoothingMode = SmoothingMode.HighSpeed;
			this.pads = new PadList();
			this.minCountOfBars = 125;
			this.canvasLeftOffset = 20;
			this.canvasTopOffset = 20;
			this.canvasRightOffset = 20;
			this.canvasBottomOffset = 30;
			this.canvasColor = Color.MidnightBlue;
			this.padsHeightArray = new ArrayList();
			this.padSplitIndex = -1;
			this.contentUpdated = true;
			this.actionType = ChartActionType.None;
			this.updateStyle = ChartUpdateStyle.Trailing;
			this.minAxisGap = 50;
			this.ContextMenuEnabled = true;
			this.LabelDigitsCount = 2;
			this.rightAxesFontSize = 7;
			this.dateTipRectangleColor = Color.LightGray;
			this.dateTipTextColor = Color.Black;
			this.valTipRectangleColor = Color.LightGray;
			this.valTipTextColor = Color.Black;
			this.crossColor = Color.DarkGray;
			this.borderColor = Color.Gray;
			this.splitterColor = Color.LightGray;
			this.candleUpColor = Color.Black;
			this.candleDownColor = Color.Lime;
			this.volumeColor = Color.SteelBlue;
			this.rightAxisGridColor = Color.DimGray;
			this.rightAxisTextColor = Color.LightGray;
			this.rightAxisMinorTickColor = Color.LightGray;
			this.rightAxisMajorTicksColor = Color.LightGray;
			this.itemTextColor = Color.LightGray;
			this.selectedItemTextColor = Color.Yellow;
			this.selectedTransactionHighlightColor = Color.LightBlue;
			this.activeStopColor = Color.Yellow;
			this.executedStopColor = Color.MediumSeaGreen;
			this.canceledStopColor = Color.Gray;
			this.dataLock = new object();
			this.lastDateTime = DateTime.MaxValue;
			this.firstDateTime = DateTime.MinValue;

			this.InitializeComponent();
			this.font = new Font(this.Font.FontFamily, (float)this.rightAxesFontSize);
			this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
			this.UpdateStyles();
			this.canvasLeftOffset = 10;
			this.canvasTopOffset = 10;
			this.canvasRightOffset = 40;
			this.canvasBottomOffset = 40;
			this.MouseWheel += new MouseEventHandler(this.HandleMouseWheel);
			this.AddPad();
			this.axisBottom = new AxisBottom(this, this.canvasLeftOffset, this.Width - this.canvasRightOffset, this.Height - this.canvasTopOffset);
			this.hScrollBar.Minimum = 0;
			this.chartBackColor = Color.MidnightBlue;
			this.firstIndex = -1;
			this.lastIndex = -1;
		}
예제 #60
0
 internal static extern GpStatus GdipGetSmoothingMode(GpGraphics graphics, out SmoothingMode smoothingMode);