Image 类

定义

为源自 BitmapMetafile 的类提供功能的抽象基类。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.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
[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
type Image = class
    inherit MarshalByRefObject
    interface ISerializable
    interface ICloneable
    interface IDisposable
Public MustInherit Class Image
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
继承
派生
属性
实现

示例

下面的代码示例旨在与 Windows 窗体一起使用。The following code example is designed for use with Windows Forms. 它是Paint事件的处理程序。It is a handler for the Paint event. Graphics对象将传递给事件,并用于在窗体上绘制图像。A Graphics object is passed to the event and is used to draw the image on the form. 该代码执行下列操作:The code performs the following actions:

  • 从名为 SampImag 的文件创建映像。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

注解

若要Image在 Windows 窗体上绘制,应使用其中一种DrawImage方法。To draw an Image on a Windows Form, you should use one of the DrawImage methods.

属性

Flags

获取该 Image 的像素数据的特性标志。Gets attribute flags for the pixel data of this Image.

FrameDimensionsList

获取 GUID 的数组,这些 GUID 表示此 Image 中帧的维数。Gets an array of GUIDs that represent the dimensions of frames within this Image.

Height

获取此 Image 的高度(以像素为单位)。Gets the height, in pixels, of this Image.

HorizontalResolution

获取此 Image 的水平分辨率(以“像素/英寸”为单位)。Gets the horizontal resolution, in pixels per inch, of this Image.

Palette

获取或设置用于此 Image 的调色板。Gets or sets the color palette used for this Image.

PhysicalDimension

获取此图像的宽度和高度。Gets the width and height of this image.

PixelFormat

获取此 Image 的像素格式。Gets the pixel format for this Image.

PropertyIdList

获取存储于该 Image 中的属性项的 ID。Gets IDs of the property items stored in this Image.

PropertyItems

获取存储于该 Image 中的所有属性项(元数据片)。Gets all the property items (pieces of metadata) stored in this Image.

RawFormat

获取此 Image 的文件格式。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

获取此 Image 的垂直分辨率(以“像素/英寸”为单位)。Gets the vertical resolution, in pixels per inch, of this Image.

Width

获取此 Image 的宽度(以像素为单位)。Gets the width, in pixels, of this Image.

方法

Clone()

创建此 Image 的一个精确副本。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.

(继承自 MarshalByRefObject)
Dispose()

释放此 Image 使用的所有资源。Releases all resources used by this Image.

Dispose(Boolean)

释放由 Image 占用的非托管资源,还可以另外再释放托管资源。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.

(继承自 Object)
Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

FromFile(String)

从指定的文件创建 ImageCreates an Image from the specified file.

FromFile(String, Boolean)

使用该文件中的嵌入颜色管理信息,从指定的文件创建 ImageCreates an Image from the specified file using embedded color management information in that file.

FromHbitmap(IntPtr)

从 GDI 位图的句柄创建 BitmapCreates a Bitmap from a handle to a GDI bitmap.

FromHbitmap(IntPtr, IntPtr)

从 GDI 位图的句柄和 GDI 调色板的句柄创建 BitmapCreates a Bitmap from a handle to a GDI bitmap and a handle to a GDI palette.

FromStream(Stream)

从指定的数据流创建 ImageCreates an Image from the specified data stream.

FromStream(Stream, Boolean)

可以选择使用指定的数据流中嵌入的颜色管理信息,从该数据流创建 ImageCreates an Image from the specified data stream, optionally using embedded color management information in that stream.

FromStream(Stream, Boolean, Boolean)

可以选择使用嵌入的颜色管理信息并验证图像数据来从指定的数据流创建 ImageCreates an Image from the specified data stream, optionally using embedded color management information and validating the image data.

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.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetPixelFormatSize(PixelFormat)

返回指定像素格式的颜色深度(每个像素的位数)。Returns the color depth, in number of bits per pixel, of the specified pixel format.

GetPropertyItem(Int32)

从该 Image 获取指定的属性项。Gets the specified property item from this Image.

GetThumbnailImage(Int32, Int32, Image+GetThumbnailImageAbort, IntPtr)

返回此 Image 的缩略图。Returns a thumbnail for this Image.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
IsAlphaPixelFormat(PixelFormat)

返回一个值,该值指示此 Image 的像素格式是否包含 alpha 信息。Returns a value that indicates whether the pixel format for this Image contains alpha information.

IsCanonicalPixelFormat(PixelFormat)

返回一个值,该值指示该像素格式是否为每个像素 32 位。Returns a value that indicates whether the pixel format is 32 bits per pixel.

IsExtendedPixelFormat(PixelFormat)

返回一个值,该值指示该像素格式是否为每个像素 64 位。Returns a value that indicates whether the pixel format is 64 bits per pixel.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
RemovePropertyItem(Int32)

从该 Image 移除指定的属性项。Removes the specified property item from this Image.

RotateFlip(RotateFlipType)

旋转、翻转或者同时旋转和翻转 ImageRotates, 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)

将该 Image 保存到指定的文件或流。Saves this Image to the specified file or stream.

Save(String, ImageCodecInfo, EncoderParameters)

使用指定的编码器和图像编码器参数,将该 Image 保存到指定的文件。Saves this Image to the specified file, with the specified encoder and image-encoder parameters.

Save(String, ImageFormat)

将此 Image 以指定格式保存到指定文件。Saves this Image to the specified file in the specified format.

SaveAdd(EncoderParameters)

将帧添加到上次对 Save 方法调用时所指定的文件或流中。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)

将帧添加到上次对 Save 方法调用时所指定的文件或流中。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)

在此 Image 中存储一个属性项(元数据片)。Stores a property item (piece of metadata) in this Image.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用将目标对象序列化所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

适用于

另请参阅