Image Class
.NET Framework 2.0
An abstract base class that provides functionality for the Bitmap and Metafile descended classes.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Assembly: System.Drawing (in system.drawing.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ <TypeConverterAttribute(GetType(ImageConverter))> _ Public MustInherit Class Image Inherits MarshalByRefObject Implements ISerializable, ICloneable, IDisposable 'Usage Dim instance As Image
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute TypeConverterAttribute(System.Drawing.ImageConverter) */ public abstract class Image extends MarshalByRefObject implements ISerializable, ICloneable, IDisposable
SerializableAttribute ComVisibleAttribute(true) TypeConverterAttribute(System.Drawing.ImageConverter) public abstract class Image extends MarshalByRefObject implements ISerializable, ICloneable, IDisposable
Not applicable.
The following code example demonstrates how to construct a new Bitmap from a file, using the GetPixel and SetPixel methods to recolor the image. It also uses the PixelFormat, Width, and Height properties.
This example is designed to be used with a Windows Forms that contains a Label, PictureBox, and Button named Label1, PictureBox1, and Button1, respectively. Paste the code into the form and associate the Button1_Click method with the button's Click event.
Dim image1 As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Try ' Retrieve the image. image1 = New Bitmap( _ "C:\Documents and Settings\All Users\Documents\My Music\music.bmp", _ True) Dim x, y As Integer ' Loop through the images pixels to reset color. For x = 0 To image1.Width - 1 For y = 0 To image1.Height - 1 Dim pixelColor As Color = image1.GetPixel(x, y) Dim newColor As Color = _ Color.FromArgb(pixelColor.R, 0, 0) image1.SetPixel(x, y, newColor) Next Next ' Set the PictureBox to display the image. PictureBox1.Image = image1 ' Display the pixel format in Label1. Label1.Text = "Pixel format: " + image1.PixelFormat.ToString() Catch ex As ArgumentException MessageBox.Show("There was an error." _ & "Check the path to the image file.") End Try End Sub
private Bitmap image1;
private void button1_Click(Object sender, System.EventArgs e)
{
try {
// Retrieve the image.
image1 = new Bitmap("C:\\Documents and Settings\\All Users\\"
+ "Documents\\My Music\\music.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for (x = 0; x < image1.get_Width(); x++) {
for (y = 0; y < image1.get_Height(); y++) {
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.get_R(), 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
pictureBox1.set_Image(image1);
// Display the pixel format in label1.
label1.set_Text("Pixel format: "
+ image1.get_PixelFormat().ToString());
}
catch (ArgumentException exp) {
MessageBox.Show(("There was an error."
+ "Check the path to the image file."));
}
} //button1_Click
System.Object
System.MarshalByRefObject
System.Drawing.Image
System.Drawing.Bitmap
System.Drawing.Imaging.Metafile
System.MarshalByRefObject
System.Drawing.Image
System.Drawing.Bitmap
System.Drawing.Imaging.Metafile
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: