C#:Bitmap类使用方法—第1讲

首先看一下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)

用指定的大小和指定的 Graphics 对象的分辨率初始化 Bitmap 类的新实例。

Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr)

用指定的大小、像素格式和像素数据初始化 Bitmap 类的新实例。

Bitmap(Int32, Int32, PixelFormat)

用指定的大小和格式初始化 Bitmap 类的新实例。

Bitmap(Stream)

从指定的数据流初始化 Bitmap 类的新实例。

Bitmap(Stream, Boolean)

从指定的数据流初始化 Bitmap 类的新实例。

Bitmap(String)

从指

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑さん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值