C# Drawing Instructions

.NET Drawing

Drawing namespace

The System.Drawing namespace provides graphical capabilities. With the tools found there, you can manipulate or create visual effects with images and primitive shapes. We provide instructions for using some of these amazing capabilities.

Note

These C# articles cover the System.Drawing namespace. They explore Image, Size, Point and Font.

Example

As an introduction, this simple console program opens an image with the Image.FromFile method. It then prints the size of the image to the console. If the program doesn't compile, try adding the assembly reference System.Drawing in Visual Studio.

Program that uses System.Drawing namespace [C#]

using System;
using System.Drawing;

class Program
{
    static void Main()
    {
	Image image = Image.FromFile("C:\\background1.png");
	Console.WriteLine(image.Size);
    }
}

Output

{Width=180, Height=110}

Colors

Color type

Colors are the end result of how the light receptors in our eyes interact with our computer monitors. Also, things in the outside world apparently have colors too. We describe the Color type in the System.Drawing namespace.

Color

Images

Image (graphical text)

Images are usually stored as bitmaps, which represent collections of colored pixels. They can also store translucency values. Examples of the Image type are given here.

Image Thumbnail Image

Sizes and Points

Illustration

If you want to draw shapes on a two-dimensional surface, you will need sizes and points. These are made up of integers and floating-point numbers.

Size SizeF Point PointF

Fonts

The Font type is also found in the System.Drawing namespace. We describe some interesting techniques of handling fonts in your programs, beginning with the Font type itself.

Font Font Exists Method

Summary

.NET Framework information

These tips will not make it possible to create elaborate graphics, but they emphasize some important things about the System.Drawing namespace in the .NET Framework. Complex three-dimensional rendering requires more advanced libraries to work with.

.NET