CodeTV.BitmapGenerator.GenerateColorKeyBitmap C# (CSharp) Method

GenerateColorKeyBitmap() public static method

public static GenerateColorKeyBitmap ( Color colorKey, bool useAntiAlias ) : Bitmap
colorKey Color
useAntiAlias bool
return System.Drawing.Bitmap
        public static Bitmap GenerateColorKeyBitmap(Color colorKey, bool useAntiAlias)
        {
            // Some drawing tools needed later
            Pen blackBorder = new Pen(Color.Black, 2.0f);
            Brush green = new SolidBrush(Color.Green);
            Font font = new Font("Tahoma", 16);
            Brush textColorKeyed = new SolidBrush(colorKey);
            Brush textColor = new SolidBrush(Color.White);

            float scale = 4.0f;

            // Create a 256x256 RGB bitmap
            //Bitmap bmp = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
            //Bitmap bmp = new Bitmap(512, 512, PixelFormat.Format24bppRgb);
            Bitmap bmp = new Bitmap(1024, 1024, PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(bmp);

            // configure antialiased drawing or not
            if (useAntiAlias)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
            }
            else
            {
                g.SmoothingMode = SmoothingMode.None;
                g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
            }

            // Clear the bitmap with the color key
            g.Clear(colorKey);

            // Draw a green circle with black border in the middle
            g.FillEllipse(green, (int)(scale * 50), (int)(scale * 50), (int)(scale * 155), (int)(scale * 155));
            g.DrawEllipse(blackBorder, (int)(scale * 50), (int)(scale * 50), (int)(scale * 155), (int)(scale * 155));

            // Draw some text in the cicle with the color key color
            g.DrawString("Some text...", font, textColorKeyed, (int)(scale * 70), (int)(scale * 120));

            // Draw some text in white elsewhere in the bitmap
            g.DrawString("Other text...", font, textColor, (int)(scale * 10), (int)(scale * 10));
            g.DrawString("Text again...", font, textColor, (int)(scale * 120), (int)(scale * 220));

            // Release GDI+ objects
            blackBorder.Dispose();
            green.Dispose();
            font.Dispose();
            textColor.Dispose();
            g.Dispose();

            // return the bitmap
            return bmp;
        }