Create a green color with an alpha component then draw a green rectangle to the bitmap in memory : Bitmap « 2D Graphics « C# / C Sharp






Create a green color with an alpha component then draw a green rectangle to the bitmap in memory

     

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form {

    protected override void OnPaint(PaintEventArgs e) {
        Graphics gForm = e.Graphics;
        gForm.FillRectangle(Brushes.White, this.ClientRectangle);
        for (int i = 1; i <= 7; ++i) {
            Rectangle r = new Rectangle(i * 40 - 15, 0, 15,
                                        this.ClientRectangle.Height);
            gForm.FillRectangle(Brushes.Orange, r);
        }

        Bitmap bmp = new Bitmap(260, 260, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
        Graphics gBmp = Graphics.FromImage(bmp);

        Color green = Color.FromArgb(0x40, 0, 0xff, 0);
        Brush greenBrush = new SolidBrush(green);
        gBmp.FillRectangle(greenBrush, 10, 10, 140, 140);
        gForm.DrawImage(bmp, 20, 20, bmp.Width, bmp.Height);

        bmp.Dispose();
        gBmp.Dispose();
        greenBrush.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

   
    
    
    
  








Related examples in the same category

1.Draw on an Bitmap
2.Resize the Bitmap using the lowest quality interpolation mode
3.Resize the Bitmap using the highest quality interpolation mode
4.Create Graphics object From Image
5.Bitmap.SetResolution
6.Bitmap property: Height, Physical Dimension, width, raw format and sizeBitmap property: Height, Physical Dimension, width, raw format and size
7.Create your own BitMapCreate your own BitMap
8.Draw shapes to the bitmap in memoryDraw shapes to the bitmap in memory
9.new Bitmap(bitmap, size)
10.Read Bitmap Size by using BinaryReader
11.Bitmap.HorizontalResolution
12.Use a color matrix to change the color properties of the image
13.Create a Bitmap image in memory and set its CompositingMode
14.Create a red color with an alpha component then draw a red circle to the bitmap in memory
15.write the pixel information to the console window
16.Double buffer with Bitmap
17.Draw an array of imagesDraw an array of images
18.Bit operation with PixelFormat.Alpha
19.PixelFormat.DontCare
20.Scale Bitmap By Percent
21.Draws Bitmap in a cell within a DataGridView
22.Bitmap Image Utils
23.Bitmap Operations
24.Make Bitmap from UIElement
25.Creates a new bitmap from a specific region of another bitmap
26.Allows drawing fonts with borders and auto centers the font on a bitmap.
27.Create New Bitmap From Image
28.Simple Resize Bmp
29.Create Thumbnail
30.Calculate the RBG projection
31.Make Thumb