首先看一下Bitmap定义:封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。 Bitmap 是用于处理由像素数据定义的图像的对象。
下面介绍一下使用的例子:
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.");
}
}
注释:
位图由图形图像的像素数据及其属性组成。 有许多标准格式可用于将位图保存到文件中。 GDI+ 支持以下文件格式:BMP、GIF、EXIF、JPG、PNG 和 TIFF。 有关支持的格式的详细信息,请参阅 位图的类型。
可以使用其中一个 Bitmap 构造函数从文件、流和其他源创建图像,并使用 方法将它们保存到流或文件系统 Save 。 使用 DrawImage 对象的 方法 Graphics 将图像绘制到屏幕或内存中。 有关使用图像文件的主题列表,请参阅 使用图像、位图、图标和图元文件。
构造函数:
| Bitmap(Image) | 从指定的现有图像初始化 Bitmap 类的新实例。 |
| Bitmap(Image, Int32, Int32) | 从指定的现有图像(缩放到指定大小)初始化 Bitmap 类的新实例。 |
| Bitmap(Image, Size) | 从指定的现有图像(缩放到指定大小)初始化 Bitmap 类的新实例。 |
| Bitmap(Int32, Int32) | 用指定的大小初始化 Bitmap 类的新实例。 |
| Bitmap(Int32, Int32, Graphics) | |
| Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) | 用指定的大小、像素格式和像素数据初始化 Bitmap 类的新实例。 |
| Bitmap(Int32, Int32, PixelFormat) | 用指定的大小和格式初始化 Bitmap 类的新实例。 |
| Bitmap(Stream) | 从指定的数据流初始化 Bitmap 类的新实例。 |
| Bitmap(Stream, Boolean) | 从指定的数据流初始化 Bitmap 类的新实例。 |
| Bitmap(String) | 从指 |

1841

被折叠的 条评论
为什么被折叠?



