|
GDI+ FAQ:
Creating Images
in memory
GDI+ FAQ: Creating images
from files
Creating a new blank image is
accomplished with the Bitmap constructor.
[C#]
Bitmap myImage = new
Bitmap(<xsize>,<ysize>);
[VB]
Dim MyImage = new
Bitmap(<xsize>,<ysize>)
This method creates an image with the default color
depth parameters. To specify a color depth, you can also specify a pixel
format parameter in the constructor.
[C#]
Bitmap myImage = new
Bitmap(<xsize>,<ysize>,PixelFormat.<format>);
[VB]
Dim MyImage = new
Bitmap(<xsize>,<ysize>,PixelFormat.<format>)
Note that indexed color images, for
example 8 bits per pixel with a color palette may not be created in this
way. An exception will be thrown and the image will be null or Nothing.
This is either a bug or an intended shortcoming.
The Pixel Formats valid for the creation of a bitmap
image are:
Format16bppArgb1555
Format16bppGrayScale
Format16bppRgb555
Format16bppRgb565
Format24bppRgb
Format32bppArgb
Format32bppPArgb
Format32bppRgb
Format48bppRgb
Format64bppArgb
Format64bppPArgb
When
created, the images memory area is cleared to 0. This means that images
may appear black and be completely transparent if the image is one capable
of storing per-pixel alpha values.
Images may be loaded from disc in any of the standard
formats (JPEG, GIF, TIFF or Windows Bitmap)
This is
performed with the Image static or shared method Image.FromFile
[C#]
Bitmap bm = (Bitmap)Image.FromFile("<filename>");
[VB]
Dim bm as Bitmap =
CType(Image.FromFile("<filename">),Bitmap)
Back to the GDI+
FAQ
|