Image Class
Definition
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Image : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
- Inheritance
- Derived
- Attributes
- Implements
Inherited Members
System.MarshalByRefObject
System.Object
Examples
The following code example is designed for use with Windows Forms. It is a handler for the Paint event. A Graphics object is passed to the event and is used to draw the image on the form. The code performs the following actions:
Creates an image from a file named SampImag.jpg. This file must be located in the same folder as the application executable file.
Creates a point at which to draw the upper-left corner of the image.
Draws the unscaled image on the form.
private:
void ImageExampleForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create Point for upper-left corner of image.
Point ulCorner = Point(100,100);
// Draw image to screen.
e->Graphics->DrawImage( newImage, ulCorner );
}
private void ImageExampleForm_Paint(object sender, PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create Point for upper-left corner of image.
Point ulCorner = new Point(100, 100);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
Private Sub ImageExampleForm_Paint _
(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create Point for upper-left corner of image.
Dim ulCorner As New Point(100, 100)
' Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner)
End Sub
Remarks
To draw an Image on a Windows Form, you should use one of the DrawImage methods.
Properties
| Flags |
Gets attribute flags for the pixel data of this Image. |
| FrameDimensionsList |
Gets an array of GUIDs that represent the dimensions of frames within this Image. |
| Height |
Gets the height, in pixels, of this Image. |
| HorizontalResolution |
Gets the horizontal resolution, in pixels per inch, of this Image. |
| Palette |
Gets or sets the color palette used for this Image. |
| PhysicalDimension |
Gets the width and height of this image. |
| PixelFormat |
Gets the pixel format for this Image. |
| PropertyIdList |
Gets IDs of the property items stored in this Image. |
| PropertyItems |
Gets all the property items (pieces of metadata) stored in this Image. |
| RawFormat |
Gets the file format of this Image. |
| Size |
Gets the width and height, in pixels, of this image. |
| Tag |
Gets or sets an object that provides additional data about the image. |
| VerticalResolution |
Gets the vertical resolution, in pixels per inch, of this Image. |
| Width |
Gets the width, in pixels, of this Image. |
Methods
| Clone() |
Creates an exact copy of this Image. |
| Dispose() |
Releases all resources used by this Image. |
| Dispose(Boolean) |
Releases the unmanaged resources used by the Image and optionally releases the managed resources. |
| Finalize() |
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. |
| FromFile(String) |
Creates an Image from the specified file. |
| FromFile(String, Boolean) |
Creates an Image from the specified file using embedded color management information in that file. |
| FromHbitmap(IntPtr) |
Creates a Bitmap from a handle to a GDI bitmap. |
| FromHbitmap(IntPtr, IntPtr) |
Creates a Bitmap from a handle to a GDI bitmap and a handle to a GDI palette. |
| FromStream(Stream, Boolean, Boolean) |
Creates an Image from the specified data stream, optionally using embedded color management information and validating the image data. |
| FromStream(Stream) |
Creates an Image from the specified data stream. |
| FromStream(Stream, Boolean) |
Creates an Image from the specified data stream, optionally using embedded color management information in that stream. |
| GetBounds(GraphicsUnit) |
Gets the bounds of the image in the specified unit. |
| GetEncoderParameterList(Guid) |
Returns information about the parameters supported by the specified image encoder. |
| GetFrameCount(FrameDimension) |
Returns the number of frames of the specified dimension. |
| GetPixelFormatSize(PixelFormat) |
Returns the color depth, in number of bits per pixel, of the specified pixel format. |
| GetPropertyItem(Int32) |
Gets the specified property item from this Image. |
| GetThumbnailImage(Int32, Int32, Image+GetThumbnailImageAbort, IntPtr) |
Returns a thumbnail for this Image. |
| IsAlphaPixelFormat(PixelFormat) |
Returns a value that indicates whether the pixel format for this Image contains alpha information. |
| IsCanonicalPixelFormat(PixelFormat) |
Returns a value that indicates whether the pixel format is 32 bits per pixel. |
| IsExtendedPixelFormat(PixelFormat) |
Returns a value that indicates whether the pixel format is 64 bits per pixel. |
| RemovePropertyItem(Int32) |
Removes the specified property item from this Image. |
| RotateFlip(RotateFlipType) |
Rotates, flips, or rotates and flips the Image. |
| Save(String, ImageCodecInfo, EncoderParameters) |
Saves this Image to the specified file, with the specified encoder and image-encoder parameters. |
| Save(Stream, ImageCodecInfo, EncoderParameters) |
Saves this image to the specified stream, with the specified encoder and image encoder parameters. |
| Save(String, ImageFormat) |
Saves this Image to the specified file in the specified format. |
| Save(Stream, ImageFormat) |
Saves this image to the specified stream in the specified format. |
| Save(String) |
Saves this Image to the specified file or stream. |
| SaveAdd(EncoderParameters) |
Adds a frame to the file or stream specified in a previous call to the Save method. Use this method to save selected frames from a multiple-frame image to another multiple-frame image. |
| SaveAdd(Image, EncoderParameters) |
Adds a frame to the file or stream specified in a previous call to the Save method. |
| SelectActiveFrame(FrameDimension, Int32) |
Selects the frame specified by the dimension and index. |
| SetPropertyItem(PropertyItem) |
Stores a property item (piece of metadata) in this Image. |
Explicit Interface Implementations
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
Populates a SerializationInfo with the data needed to serialize the target object. |