Bitmap类文档
Bitmap 类
.NET Framework 4.5 其他版本
封装 GDI+ 位图,此位图由图形图像及其特性的像素数据组成。 Bitmap 是用于处理由像素数据定义的图像的对象。
继承层次结构System::Object
System::MarshalByRefObject
System.Drawing::Image
System.Drawing::Bitmap
命名空间: System.Drawing
程序集: System.Drawing(在 System.Drawing.dll 中) 语法
C# C++ F# VB [SerializableAttribute] [ComVisibleAttribute(true)] public ref class Bitmap sealed : public Image
Bitmap 类型公开以下成员。
构造函数| Bitmap(Image) | 从指定的现有图像初始化 Bitmap 类的新实例。 | |
| Bitmap(Stream) | 从指定的数据流初始化 Bitmap 类的新实例。 | |
| Bitmap(String) | 从指定的文件初始化 Bitmap 类的新实例。 | |
| Bitmap(Image, Size) | 从指定的现有图像(缩放到指定大小)初始化 Bitmap 类的新实例。 | |
| Bitmap(Int32, Int32) | 用指定的大小初始化 Bitmap 类的新实例。 | |
| Bitmap(Stream, Boolean) | 从指定的数据流初始化 Bitmap 类的新实例。 | |
| Bitmap(String, Boolean) | 从指定的文件初始化 Bitmap 类的新实例。 | |
| Bitmap(Type, String) | 从指定的资源初始化 Bitmap 类的新实例。 | |
| Bitmap(Image, Int32, Int32) | 从指定的现有图像(缩放到指定大小)初始化 Bitmap 类的新实例。 | |
| Bitmap(Int32, Int32, Graphics) | 用指定的大小和指定的 Graphics 对象的分辨率初始化 Bitmap 类的新实例。 | |
| Bitmap(Int32, Int32, PixelFormat) | 用指定的大小和格式初始化 Bitmap 类的新实例。 | |
| Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) | 用指定的大小、像素格式和像素数据初始化 Bitmap 类的新实例。 |
| Flags | 获取该 Image 的像素数据的特性标志。 (继承自 Image。) | |
| FrameDimensionsList | 获取 GUID 的数组,这些 GUID 表示此 Image 中帧的维数。 (继承自 Image。) | |
| Height | 获取此 Image 的高度(以像素为单位)。 (继承自 Image。) | |
| HorizontalResolution | 获取此 Image 的水平分辨率(以“像素/英寸”为单位)。 (继承自 Image。) | |
| Palette | 获取或设置用于此 Image 的调色板。 (继承自 Image。) | |
| PhysicalDimension | 获取此图像的宽度和高度。 (继承自 Image。) | |
| PixelFormat | 获取此 Image 的像素格式。 (继承自 Image。) | |
| PropertyIdList | 获取存储于该 Image 中的属性项的 ID。 (继承自 Image。) | |
| PropertyItems | 获取存储于该 Image 中的所有属性项(元数据片)。 (继承自 Image。) | |
| RawFormat | 获取此 Image 的文件格式。 (继承自 Image。) | |
| Size | 获取此图像的以像素为单位的宽度和高度。 (继承自 Image。) | |
| Tag | 获取或设置提供有关图像附加数据的对象。 (继承自 Image。) | |
| VerticalResolution | 获取此 Image 的垂直分辨率(以“像素/英寸”为单位)。 (继承自 Image。) | |
| Width | 获取此 Image 的宽度(以像素为单位)。 (继承自 Image。) |
| Clone() | 创建此 Image 的一个精确副本。 (继承自 Image。) | |
| Clone(Rectangle, PixelFormat) | 创建此 Bitmap(它由 Rectangle 结构并使用指定的 PixelFormat 枚举定义)的某个部分的副本。 | |
| Clone(RectangleF, PixelFormat) | 创建此 Bitmap(用指定的 PixelFormat 枚举定义)的某个部分的副本。 | |
| CreateObjRef | 创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。 (继承自MarshalByRefObject。) | |
| Dispose() | 释放由此 Image 占用的所有资源。 (继承自 Image。) | |
| Equals(Object) | 确定指定的对象是否等于当前对象。 (继承自 Object。) | |
| FromHicon | 从图标的 Windows 句柄创建 Bitmap。 | |
| FromResource | 从指定的 Windows 资源创建 Bitmap。 | |
| GetBounds | 以指定的单位获取图像的界限。 (继承自 Image。) | |
| GetEncoderParameterList | 返回有关指定的图像编码器所支持的参数的信息。 (继承自 Image。) | |
| GetFrameCount | 返回指定维度的帧数。 (继承自 Image。) | |
| GetHashCode | 用作特定类型的哈希函数。 (继承自 Object。) | |
| GetHbitmap() | 从此 Bitmap 创建 GDI 位图对象。 | |
| GetHbitmap(Color) | 从此 Bitmap 创建 GDI 位图对象。 | |
| GetHicon | 返回图标的句柄。 | |
| GetLifetimeService | 检索控制此实例的生存期策略的当前生存期服务对象。 (继承自 MarshalByRefObject。) | |
| GetPixel | 获取此 Bitmap 中指定像素的颜色。 | |
| GetPropertyItem | 从该 Image 获取指定的属性项。 (继承自 Image。) | |
| GetThumbnailImage | 返回此 Image 的缩略图。 (继承自 Image。) | |
| GetType | 获取当前实例的 Type。 (继承自 Object。) | |
| InitializeLifetimeService | 获取控制此实例的生存期策略的生存期服务对象。 (继承自 MarshalByRefObject。) | |
| LockBits(Rectangle, ImageLockMode, PixelFormat) | 将 Bitmap 锁定到系统内存中。 | |
| LockBits(Rectangle, ImageLockMode, PixelFormat, BitmapData) | 将 Bitmap 锁定到系统内存中 | |
| MakeTransparent() | 使默认的透明颜色对此 Bitmap 透明。 | |
| MakeTransparent(Color) | 使指定的颜色对此 Bitmap 透明。 | |
| RemovePropertyItem | 从该 Image 移除指定的属性项。 (继承自 Image。) | |
| RotateFlip | 旋转、翻转或者同时旋转和翻转 Image。 (继承自 Image。) | |
| Save(String) | 将该 Image 保存到指定的文件或流。 (继承自 Image。) | |
| Save(Stream, ImageFormat) | 将此图像以指定的格式保存到指定的流中。 (继承自 Image。) | |
| Save(String, ImageFormat) | 将此 Image 以指定格式保存到指定文件。 (继承自 Image。) | |
| Save(Stream, ImageCodecInfo, EncoderParameters) | 使用指定的编码器和图像编码器参数,将该图像保存到指定的流。 (继承自 Image。) | |
| Save(String, ImageCodecInfo, EncoderParameters) | 使用指定的编码器和图像编码器参数,将该 Image 保存到指定的文件。 (继承自 Image。) | |
| SaveAdd(EncoderParameters) | 在上一 Save 方法调用所指定的文件或流内添加一帧。使用此方法将多帧图像中的选定帧保存到另一个多帧图像。 (继承自 Image。) | |
| SaveAdd(Image, EncoderParameters) | 在上一 Save 方法调用所指定的文件或流内添加一帧。 (继承自 Image。) | |
| SelectActiveFrame | 选择由维度和索引指定的帧。 (继承自 Image。) | |
| SetPixel | 设置此 Bitmap 中指定像素的颜色。 | |
| SetPropertyItem | 在此 Image 中存储一个属性项(元数据片)。 (继承自 Image。) | |
| SetResolution | 设置此 Bitmap 的分辨率。 | |
| ToString | 返回表示当前对象的字符串。 (继承自 Object。) | |
| UnlockBits | 从系统内存解锁此 Bitmap。 |
| ISerializable::GetObjectData | 使用将目标对象序列化所需的数据填充 SerializationInfo。 (继承自 Image。) |
位图由图形图像及其特性的像素数据组成。可使用许多标准格式将位图保存到文件中。GDI+ 支持下列文件格式:BMP、GIF、EXIF、JPG、PNG 和 TIFF。有关支持的格式的更多信息,请参见位图类型。
可以使用 Bitmap 构造函数中的一种来从文件、流和其他源创建图像,然后使用 Save 方法将这些图像保存到流或文件系统中。使用 Graphics 对象的 DrawImage 方法,将图像绘制到屏幕上或内存中。有关使用图像文件的主题的列表,请参见使用图像、位图、图标和图元文件。
| 不能跨应用程序域访问 Bitmap 类。例如,如果您创建了一个动态 AppDomain,并在该域中创建了几个画笔、钢笔和位图,然后将这些对象传递回主应用程序域,则您可以成功使用这些钢笔和画笔。但是,如果您调用 DrawImage 方法来绘制封送的 Bitmap,您会收到以下异常信息。 远程处理无法在类型“System.Drawing.Image”上找到字段“本机映像”。 |
下面的代码示例演示了如何使用 GetPixel 和 SetPixel 方法从文件构造新的 Bitmap,为图像重新着色。它还使用 PixelFormat、Width 和 Height 属性。
此示例旨在用于包含名为 Label1 的 Label、名为 PictureBox1 的 PictureBox 和名为 Button1 的 Button 的 Windows 窗体。将代码粘贴到该窗体中,并将Button1_Click 方法与按钮的 Click 事件关联。
C# C++ VB 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." );}} 版本信息.NET Framework
受以下版本支持:4.5、4、3.5、3.0、2.0、1.1、1.0.NET Framework Client Profile
受以下版本支持:4、3.5 SP1 平台Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(不支持服务器核心角色), Windows Server 2008 R2(支持带 SP1 或更高版本的服务器核心角色;不支持 Itanium)
.NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。 线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
转载于:https://www.cnblogs.com/songtzu/archive/2013/01/03/2843441.html
总结
- 上一篇: [leetcode]Divide Two
- 下一篇: Struts2升级注意事项