示例#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());
        }
示例#2
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();
        }