C# 关于画图Graphics Bitmap image
来源:互联网 发布:淘宝卖家中心手机版 编辑:程序博客网 时间:2024/05/09 21:20
关于GDI+ 的使用,就对点,线,面的画的操作,图像剪裁,缩放等等操作,了解各种常用的方法和属性。
常用命名空间:System.Drawing;System.Drawing.Image;System.Drawing.Drawing2D;
Graphics类封装了一个GDI+绘图图面,提供将对象绘制到显示到设备的方法。Graphics叫画板,只不过这个画板中带了很多工具。但画图时你要定义画板的大小,颜色等等,还应给他一张画纸;
Graphics
1.创建Graphics基本方法:
Graphics g = this.CreateGraphics();
Graphics g = e;// Paint事件中的
Graphics g = Graphics.FromImage();//Graphics.Fromxx类的各种静态方法。
谁创建Graphics对象,就在谁上画。
2.画的方法:
g.Drawxx 的各种方法。
3.Graphics用的 画笔和画刷
pen 和 Font pen.PenType //属性 pen.DashStyle Font f = new Font( "宋体", 15, FontStyle.Bold | FontStyle.Italic );Brush //画刷 派生类: LinearGradientBrush//渐变画刷 SolidBrush//单色画刷 HatchBrush //用阴影样式 (机械制图时用的多) TextureBrush//画字 ImageBrush//图片画刷 VisualBrush// RadialGradientBrush DrawingBrush
4.图片处理
1. Graphics.SmoothingMode //消除锯齿常用 2. Graphics.InterpolationMode //图像缩放常用 3. Graphics.CompositingQuality //
clear()方法:
Graphics g.clear(Color.Blue);// 不是清除xx颜色,是清除背景并设置xx颜色。
Bitmap ,image 和 Icon
Bitmap bmp = new Bitmap(16, 16); Bitmap bmp1 = Bitmap.FromHbitmap(bmp.GetHbitmap()); Image image = Image.FromFile(@"C:\\temp.jpg"); bmp.MakeTransparent(Color.FromArgb(255, 0, 255));//把xx颜色设置透明色 for (int i = 0; i < bmp.Width; i++) { for (int j = 0; j < bmp.Height; j++) { if (bmp.GetPixel(i, j) == Color.Blue)//获取像素设置 { bmp.SetPixel(i, j, Color.Red); } } }
ImageAttributes imageAttr = new ImageAttributes();//通过位图和图元文件颜色的信息设置颜色
imageAttr.SetColorKey(lowerColor,upperColor, ColorAdjustType.Default);
e.Graphics.DrawImage(Image, rect, 0, 0, 100, 100, GraphicsUnit.Pixel, imageAttr);
Stream IconStream = System.IO.File.OpenWrite(fileName);
Bitmap bitmap = new Bitmap(pbImage.Image);
bitmap.SetResolution(32, 32);
Icon icon = System.Drawing.Icon.FromHandle(bitmap.GetHicon());
icon.Save(IconStream);//比bitmap.save格式强点
其他常用:
Clipboard.SetDataObject(this.pbSource.Image);//截图 IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) image = (Bitmap)data.GetData(DataFormats.Bitmap); Color c = KnownColor.Control; Color c =SystemColors.Control Color c = Color.FromArgb(128, Color.Blue); //128为半透明颜色 this.Opacity = 0.5//窗体的透明度 System.Drawing.Drawing2D 命名空间下GraphicsPath //创建矢量图 Bitmap bmp = new Bitmap(220,220); Graphics g = Graphics.FromImage(bmp); Metafile mf = new Metafile(filePath,g.GetHdc()); //画图... g.Save(); g.Dispose(); mf.Dispose();
防止图片闪烁,双缓冲设置
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.SupportsTransparentBackColor, true);
尽量不要用窗体TransparencyKey否则闪烁和卡顿会使用闪烁更严重。 不要在Paint事件给各种 xx.Image 赋值,xx.Image会调用paint这样会死循环。图像的各种效果(底片、浮雕、黑白、滤镜)只是算法问题。
- C# 关于画图Graphics Bitmap image
- C# 使用Graphics画图
- C# System.Drawing Graphics 画图
- C#中Graphics的画图代码【转】
- C#中Graphics的画图代码【转】
- graphics画图
- Bitmap、Graphics
- c#通过Graphics处理图片以及画图(初步学习1)
- c# Icon 转 Bitmap 转 Image
- 关于画图那些简单的事(graphics)
- 关于bitmap recycle trying to use a recycled bitmap android.graphics.Bitmap
- 关于C# Winform的画图
- java graphics 画图
- 画图-Graphics 类简介
- java 画图 graphics
- 基于Graphics画图
- 关于异常Canvas: trying to use a recycled bitmap android.graphics.Bitmap的解决
- android.graphics.Bitmap 一
- rewrite 防止迅雷下载
- Odat渗透攻击oracle资源链接
- 因缺思汀的绕过
- Windows 内核 进程 线程 初探~
- pycharm下的Python console 调试当前程序方法
- C# 关于画图Graphics Bitmap image
- C++中继承关系中的同名隐藏和对策
- 由浅入深理解android 消息机制
- STM32——定时器TIME模块之PWM输出
- 纹理过滤
- (二)Vue.js 条件判断 20170818
- HTML文档
- C# Redis
- GreenDao 3.2.0 的基本使用