Draw on an Bitmap

image_pdfimage_print
   
  

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) {
    Bitmap bmp = new Bitmap(100, 100);
    Graphics gImage = Graphics.FromImage(bmp);
    gImage.FillRectangle(Brushes.Red, 0, 0, bmp.Width, bmp.Height);
    gImage.DrawRectangle(Pens.Black, 10, 10, bmp.Width - 20, bmp.Height - 20);

    Graphics gScreen = e.Graphics;
    gScreen.FillRectangle(Brushes.White, this.ClientRectangle);
    gScreen.DrawImage(bmp, new Rectangle(10, 10, bmp.Width, bmp.Height));

    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

   
     


This entry was posted in 2D Graphics. Bookmark the permalink.