1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Bitmap
A class in the System.Drawing namespace that represents a raster image composed of pixels and provides operations for creating, loading, manipulating, and saving bitmap images. Domain: C# → .NET → System.Drawing → Raster Image Representation & Manipulation
Bitmap image = new Bitmap(800, 600);
Creates an empty bitmap that is 800 pixels wide and 600 pixels high.
Bitmap image = new Bitmap(800, 600, PixelFormat.Format32bppArgb);
Creates a bitmap with the specified width, height, and pixel format; this example uses a 32-bit ARGB pixel representation.
Bitmap image = new Bitmap("photo.png");
Loads a bitmap image from the specified image file.
Bitmap copy = new Bitmap(image);
Creates a new Bitmap from an existing Image object.
Bitmap resized = new Bitmap(image, 400, 300);
Creates a new Bitmap from an existing image and scales it to the specified width and height.
int width = image.Width;
Gets the width of the bitmap in pixels.
int height = image.Height;
Gets the height of the bitmap in pixels.
Size size = image.Size;
Gets the width and height of the bitmap together as a Size structure.
Color color = image.GetPixel(x, y);
Gets the Color of the pixel located at the specified x and y coordinates.
image.SetPixel(x, y, Color.Red);
Sets the pixel at the specified x and y coordinates to the specified Color.
image.Save("output.png");
Saves the bitmap to the specified file.
image.Save("output.png", ImageFormat.Png);
Saves the bitmap to a file using the PNG image format.
image.Save("output.jpg", ImageFormat.Jpeg);
Saves the bitmap to a file using the JPEG image format.
PixelFormat format = image.PixelFormat;
Gets the pixel format that describes how color information is stored for each pixel in the bitmap.
ImageFormat format = image.RawFormat;
Gets the original or raw image format associated with the image, such as PNG, JPEG, or BMP.
float horizontal = image.HorizontalResolution;
Gets the horizontal resolution of the bitmap in dots per inch (DPI).
float vertical = image.VerticalResolution;
Gets the vertical resolution of the bitmap in dots per inch (DPI).
image.SetResolution(300, 300);
Sets the horizontal and vertical resolution metadata of the bitmap to 300 DPI without changing its pixel dimensions.
image.MakeTransparent();
Makes the bitmap's default transparency color transparent.
image.MakeTransparent(Color.White);
Makes pixels matching the specified color transparent.
Bitmap copy = image.Clone(rectangle, image.PixelFormat);
Copies the specified rectangular region of the bitmap into a new Bitmap using the specified pixel format.
BitmapData data = image.LockBits(rectangle, ImageLockMode.ReadWrite, image.PixelFormat);
Locks a region of bitmap pixel data in memory for direct, lower-level, and potentially faster pixel access.
image.UnlockBits(data);
Unlocks bitmap data that was previously locked with LockBits().
IntPtr pointer = data.Scan0;
Gets a pointer to the first byte of the locked bitmap data in memory.
int stride = data.Stride;
Gets the number of bytes between the beginning of one scan line of bitmap data and the beginning of the next.
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
Rotates the bitmap by 90 degrees without flipping it; other RotateFlipType values can specify different rotations and flips.
image.Dispose();
Releases the resources associated with the Bitmap.
using Bitmap image = new Bitmap("photo.png");
Creates a Bitmap that is automatically disposed when execution leaves its scope.
Raster Image
An image represented as a rectangular grid of individual pixels.
Pixel
The individual picture element of a raster image that stores color information for one position in the image.
Pixel Format
The organization and number of bits used to represent each pixel's color information, such as a 32-bit format containing alpha, red, green, and blue channels.
DPI
Dots Per Inch; resolution metadata describing an image's intended physical pixel density. Changing DPI does not by itself change the bitmap's pixel dimensions.
Stride
The number of bytes between the beginning of one bitmap scan line and the beginning of the next row in memory, which may include padding beyond the visible pixel data.