System.Drawing.Drawing2D.PathGradientBrush.TranslateTransform C# (CSharp) Method

TranslateTransform() public method

public TranslateTransform ( float dx, float dy ) : void
dx float
dy float
return void
        public void TranslateTransform(float dx, float dy)
        {
            this.TranslateTransform(dx, dy, MatrixOrder.Prepend);
        }

Same methods

PathGradientBrush::TranslateTransform ( float dx, float dy, MatrixOrder order ) : void

Usage Example

示例#1
0
        public static byte[] CreateShadowImage(
            ShadowImageType imageType,
            int Width,
            int Height,
            Color ShadowColor,
            Color BackColor,
            ImageFormat Format)
        {
            MemoryStream memStream = new MemoryStream();
            Bitmap bmpPaint = new Bitmap(Width,Height);
            Graphics grph = Graphics.FromImage(bmpPaint);

            if ( imageType == ShadowImageType.Blank )
            {
                SolidBrush brush;
                brush = new SolidBrush(BackColor);
                grph.FillRectangle(brush,0,0,Width,Height);
            }
            else if ( imageType == ShadowImageType.Top || imageType == ShadowImageType.Bottom ||
                      imageType == ShadowImageType.Left || imageType == ShadowImageType.Right )
            {
                int angle=0;
                switch( imageType )
                {
                    case ShadowImageType.Top:
                        angle = 270; break;
                    case ShadowImageType.Right:
                        angle = 0; break;
                    case ShadowImageType.Bottom:
                        angle = 90; break;
                    case ShadowImageType.Left:
                        angle = 180; break;
                }
                LinearGradientBrush brush;
                brush = new LinearGradientBrush(
                    new Rectangle(0,0,Width,Height),
                    ShadowColor,
                    BackColor,
                    angle,true);
                brush.Blend = shadowBlendScaleLinear;
                grph.FillRectangle(brush,0,0,Width,Height);
            }
            else
            {
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse(0, 0, Width*2,Height*2);
                PathGradientBrush brush = new PathGradientBrush(path);
                brush.CenterColor = ShadowColor;
                Color[] colors = {BackColor};
                brush.SurroundColors = colors;
                if ( imageType == ShadowImageType.BottomRight )
                {
                    brush.TranslateTransform(-Width,-Height);
                }
                else if ( imageType == ShadowImageType.TopRight )
                {
                    brush.TranslateTransform(-Width,0);
                }
                else if ( imageType == ShadowImageType.BottomLeft )
                {
                    brush.TranslateTransform(0,-Height);
                }
                brush.CenterPoint=new PointF(Width,Height);
                brush.Blend = shadowBlendScaleRadial;
                grph.FillRectangle(new SolidBrush(BackColor),0, 0, Width, Height);
                grph.FillRectangle(brush, 0, 0, Width, Height);
            }

            bmpPaint.Save(memStream,Format);
            return memStream.GetBuffer();
        }
All Usage Examples Of System.Drawing.Drawing2D.PathGradientBrush::TranslateTransform