Double buffer with Bitmap : Bitmap « 2D Graphics « C# / C Sharp






Double buffer with Bitmap

     
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form {
    Pen p;
    SolidBrush b, bT = new SolidBrush(Color.Black);
    string path = "5.bmp";
    Image im;
    Font f;

    public Form1() {
        Color cP = Color.Gray;
        Color cB = Color.LightGray;

        p = new Pen(cP, 6);
        b = new SolidBrush(cB);
        im = Image.FromFile(path);
        f = new Font(new FontFamily("Times New Roman"), 10);
    }
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs pea) {
        Sketch();
        //SketchDBuf();
    }
    private void Sketch() {
        Graphics g = Graphics.FromHwnd(this.Handle);

        g.FillRectangle(b, 4, 4, 260, 220);
        g.DrawRectangle(p, 4, 4, 260, 220);
        g.DrawImage(im, 33, 35, 200, 145);
        g.DrawString("AAAAAA", f, bT, 180, 190);

        g.Dispose();
    }
    private void SketchDBuf() {
        int hh = 3, w = 260, h = 220;

        Graphics g;
        Bitmap bm = new Bitmap(w + 2 * hh, h + 2 * hh);
        g = Graphics.FromImage(bm);

        g.FillRectangle(b, hh, hh, w, h);
        g.DrawRectangle(new Pen(Color.Gray, 2 * hh), hh, hh, w, h);
        g.DrawImage(im, hh + 30, hh + 32, 200, 145);
        g.DrawString("Text", f, bT, 180, 190);
        g = Graphics.FromHwnd(this.Handle);
        g.DrawImage(bm, 1, 1);

        g.Dispose();
    }
}

   
    
    
    
  








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.Create a green color with an alpha component then draw a green rectangle to the bitmap in memory
16.write the pixel information to the console window
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