Create Graphics object From Image : Bitmap « 2D Graphics « C# / C Sharp






Create Graphics object From Image

     

using System;
using System.Drawing;
using System.Windows.Forms;
   
class HelloWorldBitmap: Form
{
     const  float fResolution = 300;
     Bitmap bitmap = new Bitmap(1, 1);
   
     public static void Main()
     {
          Application.Run(new HelloWorldBitmap());
     }
     public HelloWorldBitmap()
     {
          ResizeRedraw = true; 
          
          bitmap.SetResolution(fResolution, fResolution);
   
          Graphics grfx = Graphics.FromImage(bitmap);
          Font     font = new Font("Times New Roman", 72);
          Size     size = grfx.MeasureString(Text, font).ToSize();
   
          bitmap = new Bitmap(bitmap, size);
          bitmap.SetResolution(fResolution, fResolution);
               
          grfx = Graphics.FromImage(bitmap);
          grfx.Clear(Color.White);
          grfx.DrawString(Text, font, Brushes.Black, 0, 0);
          grfx.Dispose();
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          grfx.DrawImage(bitmap, 0, 0);
     }
}

   
    
    
    
  








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.Bitmap.SetResolution
5.Bitmap property: Height, Physical Dimension, width, raw format and sizeBitmap property: Height, Physical Dimension, width, raw format and size
6.Create your own BitMapCreate your own BitMap
7.Draw shapes to the bitmap in memoryDraw shapes to the bitmap in memory
8.new Bitmap(bitmap, size)
9.Read Bitmap Size by using BinaryReader
10.Bitmap.HorizontalResolution
11.Use a color matrix to change the color properties of the image
12.Create a Bitmap image in memory and set its CompositingMode
13.Create a red color with an alpha component then draw a red circle to the bitmap in memory
14.Create a green color with an alpha component then draw a green rectangle 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