Assembly : System.Drawing (dans system.drawing.dll)
Syntaxe<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public MustInherit Class Image Inherits MarshalByRefObject Implements ISerializable, ICloneable, IDisposable
Dim instance As Image
[SerializableAttribute] [ComVisibleAttribute(true)] public abstract class Image : MarshalByRefObject, ISerializable, ICloneable, IDisposable
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class Image abstract : public MarshalByRefObject, ISerializable, ICloneable, IDisposable
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public abstract class Image extends MarshalByRefObject implements ISerializable, ICloneable, IDisposable
SerializableAttribute ComVisibleAttribute(true) public abstract class Image extends MarshalByRefObject implements ISerializable, ICloneable, IDisposable
ExempleL'exemple de code suivant montre comment construire un nouveau Bitmap à partir d'un fichier, en utilisant les méthodes GetPixel et SetPixel pour recolorier l'image. Il utilise également les propriétés PixelFormat, Width et Height.
Cet exemple a été conçu pour être utilisé avec un Windows Form qui contient un Label, un PictureBox et un Button nommés respectivement Label1, PictureBox1 et Button1. Collez le code dans le formulaire et associez la méthode Button1_Click à l'événement Click du bouton.
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
Bitmap image1; private void Button1_Click(System.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.Width; x++) { for(y=0; y<image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.R, 0, 0); image1.SetPixel(x, y, newColor); } } // Set the PictureBox to display the image. PictureBox1.Image = image1; // Display the pixel format in Label1. Label1.Text = "Pixel format: "+image1.PixelFormat.ToString(); } catch(ArgumentException) { MessageBox.Show("There was an error." + "Check the path to the image file."); } }
private: Bitmap^ image1; void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { try { // Retrieve the image. image1 = gcnew Bitmap( "C:\\Documents and Settings\\All Users\\" "Documents\\My Music\\music.bmp",true ); int x; int y; // Loop through the images pixels to reset color. for ( x = 0; x < image1->Width; x++ ) { for ( y = 0; y < image1->Height; y++ ) { Color pixelColor = image1->GetPixel( x, y ); Color newColor = Color::FromArgb( pixelColor.R, 0, 0 ); image1->SetPixel( x, y, newColor ); } } // Set the PictureBox to display the image. PictureBox1->Image = image1; // Display the pixel format in Label1. Label1->Text = String::Format( "Pixel format: {0}", image1->PixelFormat ); } catch ( ArgumentException^ ) { MessageBox::Show( "There was an error." "Check the path to the image file." ); } }
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
Hiérarchie d'héritageSystem.MarshalByRefObject
System.Drawing.Image
System.Drawing.Bitmap
System.Drawing.Imaging.Metafile
Sécurité des threads
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ