Winform窗体学习笔记 第二十一篇 Bitmap类

1. Bitmap 是用于处理由像素数据定义的图像的对象。

2. Bitmap 构造函数:

  • Bitmap(Image):从指定的现有图像初始化 Bitmap 类的新实例。
  • Bitmap(Stream):从指定的数据流初始化 Bitmap 类的新实例。
  • Bitmap(String):从指定的文件初始化 Bitmap 类的新实例。
  • Bitmap(Int32, Int32):用指定的大小初始化 Bitmap 类的新实例。

    复制代码

     1             Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
     2             int w = pictureBox1.Width;
     3             int h = pictureBox1.Height;
     4 
     5             for (int i = 0; i < pictureBox1.Width;i++ )
     6             {
     7                 w = i;
     8                 if(i>pictureBox1.Width/2)
     9                     w = pictureBox1.Width - i;
    10 
    11                 for (int j = 0; j < pictureBox1.Height;j++ )
    12                 {
    13                     h = j;
    14                     if (j > pictureBox1.Height/2)
    15                         h = pictureBox1.Height - j;
    16                     
    17                     b.SetPixel(i, j, Color.FromArgb(0, w, h));
    18                 }
    19             }
    20 
    21             pictureBox1.Image = b;

    复制代码

    复制代码

     1             Bitmap a = new Bitmap(245, 174);
     2             for (int i = 0; i < 245; i++)
     3             {
     4                 for (int j = 0; j < 174; j++)
     5                 {
     6                     a.SetPixel(i, j, Color.FromArgb(255,i,j));
     7                 }
     8             }
     9             pictureBox3.Refresh();
    10             pictureBox3.Image = a;

    复制代码

3. Bitmap 方法:

  • GetPixel(x, y):获取此 Bitmap 中指定像素的颜色。【屌】
  • SetPixel(x, y, color):设置此 Bitmap 中指定像素的颜色。
  • MakeTransparent:使默认的透明颜色对此 Bitmap 透明。
  • MakeTransparent(Color):使指定的颜色对此 Bitmap 透明。
  • FromHicon(IntPtr hicon):从图标的 Windows 句柄创建 Bitmap。【静态】
  • FromHBitmap(IntPtr hbitmap):【静态】。
  • Save(String):将该 Image 保存到指定的文件或流。
  • Save(String, ImageFormat):将此 Image 以指定格式保存到指定文件。
  • RotateFlip:旋转、翻转或者同时旋转和翻转 Image。【枚举】

4. Bitmap 属性:

  • Height:获取此 Image 的高度(以像素为单位)。
  • Width:获取此 Image 的宽度(以像素为单位)。
  • HorizontalResolution:获取此 Image 的水平分辨率(以“像素/英寸”为单位)。
  • VerticalResolution:获取此 Image 的垂直分辨率(以“像素/英寸”为单位)。

 

command = axToolbarControl1.CommandPool.get_Command(0);
Bitmap uiIcon = new Bitmap(@"E:\PICTURES\头像\海贼王.bmp");
//Bitmap uiIcon = Bitmap.FromHbitmap((IntPtr)command.Bitmap);
uiIcon.Save(@"F:\Desktop\1.bmp");

 

效果:

左下角一个变成了透明的了,提取的是左上角第一个像素点的颜色来实现的!

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值