Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Load and Display Bitmaps

To load a bitmap from a file and display that bitmap on the screen, you need a Bitmap object and a Graphics object. The Bitmap class supports several file formats, including BMP, GIF, JPEG, PNG, and TIFF. Pass the name of a file to the Bitmap constructor. After you have created a Bitmap object, pass that Bitmap object to the DrawImage method of a Graphics object.

Example

This example creates a Bitmap object from a JPEG file and then draws the bitmap with its upper-left corner at (60, 10).

The following illustration shows the bitmap drawn at the specified location.

Image Position
Bitmap bitmap = new Bitmap("Grapes.jpg");
e.Graphics.DrawImage(bitmap, 60, 10);

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft