Επεξεργασία

Κοινή χρήση μέσω


Image Class

Definition

An abstract base class that provides functionality for the Bitmap and Metafile descended classes.

public ref class Image abstract : MarshalByRefObject, ICloneable, IDisposable, System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))]
[System.Serializable]
public abstract class Image : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Image : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))]
public abstract class Image : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter("System.Drawing.ImageConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public abstract class Image : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))>]
[<System.Serializable>]
type Image = class
    inherit MarshalByRefObject
    interface IDisposable
    interface ICloneable
    interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Image = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.ImageConverter))>]
type Image = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
[<System.ComponentModel.TypeConverter("System.Drawing.ImageConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Image = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
    interface ISerializable
Public MustInherit Class Image
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
Inheritance
Derived
Attributes
Implements

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, use one of the DrawImage methods.

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

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.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by this Image.

Dispose(Boolean)

Releases the unmanaged resources used by the Image and optionally releases the managed resources.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

FromFile(String, Boolean)

Creates an Image from the specified file using embedded color management information in that file.

FromFile(String)

Creates an Image from the specified file.

FromHbitmap(IntPtr, IntPtr)

Creates a Bitmap from a handle to a GDI bitmap and a handle to a GDI palette.

FromHbitmap(IntPtr)

Creates a Bitmap from a handle to a GDI bitmap.

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, Boolean)

Creates an Image from the specified data stream, optionally using embedded color management information in that stream.

FromStream(Stream)

Creates an Image from the specified data 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.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
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.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
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.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
RemovePropertyItem(Int32)

Removes the specified property item from this Image.

RotateFlip(RotateFlipType)

Rotates, flips, or rotates and flips the Image.

Save(Stream, ImageCodecInfo, EncoderParameters)

Saves this image to the specified stream, with the specified encoder and image encoder parameters.

Save(Stream, ImageFormat)

Saves this image to the specified stream in the specified format.

Save(String, ImageCodecInfo, EncoderParameters)

Saves this Image to the specified file, with the specified encoder and image-encoder parameters.

Save(String, ImageFormat)

Saves this Image to the specified file 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.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the target object.

Applies to

See also