Esempio n. 1
0
        /// <summary>
        /// Returns the image of the gradient filled rounded rectangle
        /// </summary>
        /// <param name="rc">Desctination rectangle</param>
        /// <param name="startColorValue">Starting color for gradient</param>
        /// <param name="endColorValue">End color for gradient</param>
        /// <param name="borderColor">The color of the border</param>
        /// <param name="size">The size of the rounded corners</param>
        /// <returns>Bitmap image</returns>
        public static Bitmap GetGradiendRoundedRectangle(Rectangle rc, Color startColorValue, Color endColorValue, Color borderColor, Size size)
        {
            Bitmap outputImage = new Bitmap(rc.Width, rc.Height);
            // Create temporary graphics
            Graphics gx = Graphics.FromImage(outputImage);

            GradientFill.Fill(
                gx,
                rc,
                startColorValue,
                endColorValue,
                FillDirection.TopToBottom);

            Rectangle roundedRect = rc;

            roundedRect.Width--;
            roundedRect.Height--;

            Bitmap borderImage = ImposeRoundedRectangle(roundedRect, borderColor, size);

            ImageAttributes attrib = new ImageAttributes();

            attrib.SetColorKey(Color.Green, Color.Green);

            gx.DrawImage(borderImage, rc, 0, 0, borderImage.Width, borderImage.Height, GraphicsUnit.Pixel, attrib);

            // Clean up
            attrib.Dispose();
            gx.Dispose();

            return(outputImage);
        }
Esempio n. 2
0
 /// <summary>
 /// Fills the rectagle with gradient colors
 /// </summary>
 /// <param name="gx">Destination graphics</param>
 /// <param name="rc">Desctination rectangle</param>
 /// <param name="startColorValue">Starting color for gradient</param>
 /// <param name="endColorValue">End color for gradient</param>
 /// <param name="fillDirection">The direction of the gradient</param>
 public static void FillGradientRectangle(this Graphics gx, Rectangle rc, Color startColorValue, Color endColorValue, FillDirection fillDirection)
 {
     GradientFill.Fill(
         gx,
         rc,
         startColorValue,
         endColorValue,
         fillDirection);
 }
Esempio n. 3
0
        /// <summary>
        /// Returns the rectangle filled with gradient colors
        /// </summary>
        /// <param name="rc">Destination rectangle</param>
        /// <param name="startColorValue">Starting color for gradient</param>
        /// <param name="endColorValue">End color for gradient</param>
        /// <param name="fillDirection">The direction of the gradient</param>
        /// <returns>Image of the rectanle</returns>
        public static Bitmap GetGradientRectangle(Rectangle rc, Color startColorValue, Color endColorValue, FillDirection fillDirection)
        {
            Bitmap outputImage = new Bitmap(rc.Width, rc.Height);
            // Create temporary graphics
            Graphics gx = Graphics.FromImage(outputImage);

            GradientFill.Fill(
                gx,
                rc,
                startColorValue,
                endColorValue,
                fillDirection);

            return(outputImage);
        }
Esempio n. 4
0
        /// <summary>
        /// Draws gradient filled rounded rectangle with transparency
        /// </summary>
        /// <param name="gx">Destination graphics</param>
        /// <param name="rc">Destination rectangle</param>
        /// <param name="startColorValue">Starting color for gradient</param>
        /// <param name="endColorValue">End color for gradient</param>
        /// <param name="borderColor">The color of the border</param>
        /// <param name="size">The size of the rounded corners</param>
        /// <param name="transparency">Transparency constant</param>
        public static void DrawGradientRoundedRectangleAlpha(this Graphics gx, Rectangle rc, Color startColorValue, Color endColorValue, Color borderColor, Size size, byte transparency)
        {
            // Prepare image for gradient
            Bitmap gradientImage = new Bitmap(rc.Width, rc.Height);
            // Create temporary graphics
            Graphics gxGradient = Graphics.FromImage(gradientImage);
            // This is our rectangle
            Rectangle roundedRect = new Rectangle(0, 0, rc.Width, rc.Height);

            // Fill in gradient
            GradientFill.Fill(
                gxGradient,
                roundedRect,
                startColorValue,
                endColorValue,
                FillDirection.TopToBottom);

            // Prepare the copy of the screen graphics
            Bitmap   tempBitmap = new Bitmap(240, 320);
            Graphics tempGx     = Graphics.FromImage(tempBitmap);

            // Copy from the screen's graphics to the temp graphics
            CopyGraphics(gx, tempGx, 240, 320);
            // Draw the gradient image with transparency on the temp graphics
            tempGx.DrawAlpha(gradientImage, transparency, rc.X, rc.Y);
            // Cut out the transparent image
            gxGradient.DrawImage(tempBitmap, new Rectangle(0, 0, rc.Width, rc.Height), rc, GraphicsUnit.Pixel);
            // Prepare for imposing
            roundedRect.Width--;
            roundedRect.Height--;
            // Impose the rounded rectangle with transparent color
            Bitmap borderImage = ImposeRoundedRectangle(roundedRect, borderColor, size);
            // Draw the transparent rounded rectangle
            ImageAttributes attrib = new ImageAttributes();

            attrib.SetColorKey(Color.Green, Color.Green);
            gxGradient.DrawImage(borderImage, new Rectangle(0, 0, rc.Width, rc.Height), 0, 0, borderImage.Width, borderImage.Height, GraphicsUnit.Pixel, attrib);
            // OK... now are ready to draw the final image on the original graphics
            gx.DrawImageTransparent(gradientImage, rc);

            // Clean up
            attrib.Dispose();
            tempGx.Dispose();
            tempBitmap.Dispose();
            gradientImage.Dispose();
            gxGradient.Dispose();
        }