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");
效果:
左下角一个变成了透明的了,提取的是左上角第一个像素点的颜色来实现的!