常用图形绘制

<%@ Page ContentType="image/gif" Language="C#" %>
<!--ContentType设置页面类型-->
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>
<%@ Import namespace="System.Drawing.Drawing2D" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(, );
//创建一个宽400,高200的实例
Graphics gph;
//从指定的Image对象创建新Graphics对象
gph = Graphics.FromImage(bmp);
gph.SmoothingMode = SmoothingMode.HighQuality;
//设置图片质量,指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘
gph.Clear(Color.Red);
//清除整个绘图面并以指定背景色填充
gph.DrawRectangle(Pens.Blue, , , , );
gph.FillRectangle(Brushes.Blue, , , , );
//绘制矩形
gph.DrawEllipse(Pens.Blue, , , , );
gph.FillEllipse(Brushes.Blue, , , , );
//绘制椭圆
gph.DrawPie(Pens.Blue, , , , , , );
//绘制圆弧
gph.FillPie(Brushes.Blue, , , , , , );
//绘制饼图
Point[] line={new Point(,),new Point(,),new Point(,),new Point(,)};
gph.DrawCurve(Pens.Blue, line);
//绘制曲线
gph.DrawBezier(Pens.Blue, new Point(, ), new Point(, ), new Point(, ), new Point(, ));
//绘制贝塞尔曲线
Point[] line2 ={ new Point(, ), new Point(, ), new Point(, ), new Point(, ) };
gph.DrawPolygon(Pens.Blue, line2);
//gph.FillPolygon(Pens.Blue, line2);
//绘制多边形
Bitmap mybit=new Bitmap(Server.MapPath("001.jpg"));
gph.DrawImage(mybit,,,,);
//绘制图片
gph.DrawLine(Pens.Black, , , , );
//绘制直线
bmp.Save(Response.OutputStream, ImageFormat.Gif);//ImageFormat 对象,它指定保存的图像的格式
//向客户端输出数据流,并以此数据流形成Gif图片
}
</script>

绘制文本字符串

<%@ Page ContentType="image/gif" Language="C#" %>
<!--ContentType设置页面类型-->
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>
<%@ Import namespace="System.Drawing.Drawing2D" %>
<%@ Import namespace="System.Drawing.Text" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(, );
//创建一个宽400,高200的实例
Graphics gph;
//从指定的Image对象创建新Graphics对象
gph = Graphics.FromImage(bmp);
gph.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
//设置字符串质量
gph.Clear(Color.Red);
//清除整个绘图面并以指定背景色填充
gph.DrawString("无换行显示:绘制文本换行显示的字符串,应该使用文本外部边界的长方行", new Font("宋体", ), Brushes.Blue, , );
//绘制文本字符串string, Font, Brush, float, float(字符串,字体,x,y坐标)
RectangleF rect = new RectangleF(, , , );
string str = "绘制文本换行显示的字符串,应该使用文本外部边界的长方行";
gph.DrawString(str, new Font("宋体", ), Brushes.Blue,rect);
//绘制有范围的字符串
bmp.Save(Response.OutputStream, ImageFormat.Gif);//ImageFormat 对象,它指定保存的图像的格式
//向客户端输出数据流,并以此数据流形成Gif图片
}
</script>

设置图片质量

SmoothingMode 枚举 指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘

成员名称 说明 
AntiAlias 指定消除锯齿的呈现。 
Default 指定默认模式。 
HighQuality 指定高质量、低速度呈现。 
HighSpeed 指定高速度、低质量呈现。 
Invalid 指定一个无效模式。 
None 指定不消除锯齿。

<%@ ContentType="image/jpeg" Language="C#" %>
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>
<%@ Import namespace="System.Drawing.Drawing2D" %>
<%@ Import namespace="System.Drawing.Text" %>
<script language="C#" runat=server>
void Page_Load(Object sender , EventArgs e)
{
Bitmap objBitmap;
Graphics objGraphics;
Pen objPen;
Brush objBrush;
Font objFont;
objBitmap = new Bitmap( , );
objGraphics = Graphics.FromImage( objBitmap );
objPen = new Pen( Color.Yellow );
objBrush = new SolidBrush( Color.Yellow );
objFont = new Font( "Lucida Sans Unicode", );
objGraphics.SmoothingMode = SmoothingMode.Default;
objGraphics.DrawString( "Default", objFont, objBrush, , );
objGraphics.DrawEllipse( objPen, , , , );
objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
objGraphics.DrawString( "AntiAlias", objFont, objBrush, , );
objGraphics.DrawEllipse( objPen, , , , );
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
objGraphics.DrawString( "HighQuality", objFont, objBrush, , );
objGraphics.DrawEllipse( objPen, , , , );
objGraphics.SmoothingMode = SmoothingMode.HighSpeed;
objGraphics.DrawString( "HighSpeed", objFont, objBrush, , );
objGraphics.DrawEllipse( objPen, , , , );
objGraphics.SmoothingMode = SmoothingMode.None;
objGraphics.DrawString( "None", objFont, objBrush, , );
objGraphics.DrawEllipse( objPen, , , , );
objBitmap.Save( Response.OutputStream, ImageFormat.Jpeg );
}
</Script>

设置文本质量
TextRenderingHint 枚举 指定文本呈现的质量

成员名称 说明 
AntiAlias 指定在无提示的情况下使用每个字符的 AntiAlias 标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到改善。由于关闭了提示,主干宽度差可能会比较明显。 
AntiAliasGridFit 指定在有提示的情况下使用每个字符的 AntiAlias 标志符号位图来绘制字符。由于采用了 AntiAlias,质量会得到大大改善,但同时会增加性能成本。 
ClearTypeGridFit 指定在有提示的情况下使用每个字符的标志符号 CT 位图来绘制字符。这是质量最高的设置。用于利用 ClearType 字体功能。 
SingleBitPerPixel 指定使用每个字符的标志符号位图来绘制字符。不使用提示。 
SingleBitPerPixelGridFit 指定使用每个字符的标志符号位图来绘制字符。提示用于改善字符在主干和弯曲部分的外观。 
SystemDefault 指定在有系统默认呈现提示的情况下使用每个字符的标志符号位图来绘制字符。将采用用户为系统选择的所有字体修匀设置来绘制文本。

<%@ Page ContentType="image/jpeg" Language="C#" %>
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>
<%@ Import namespace="System.Drawing.Text" %>
<script language="C#" runat=server>
void Page_Load(Object sender , EventArgs e)
{
Bitmap objBitmap;
Graphics objGraphics;
string strString;
objBitmap = new Bitmap( , );
objGraphics = Graphics.FromImage( objBitmap );
objGraphics.Clear( Color.DarkBlue );
Font objFont = new Font( "Times", );
strString = "ABCabc123 - AntiAlias";
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
objGraphics.DrawString( strString, objFont, Brushes.White, , );
strString = "ABCabc123 - AntiAliasGridFit";
objGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
objGraphics.DrawString( strString, objFont, Brushes.White, , );
strString = "ABCabc123 - ClearTypeGridFit";
objGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
objGraphics.DrawString( strString, objFont, Brushes.White, , );
strString = "ABCabc123 - SingleBitPerPixel";
objGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
objGraphics.DrawString( strString, objFont, Brushes.White, , );
strString = "ABCabc123 - SingleBitPerPixelGridFit";
objGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
objGraphics.DrawString( strString, objFont, Brushes.White, , );
strString = "ABCabc123 - SystemDefault";
objGraphics.TextRenderingHint = TextRenderingHint.SystemDefault;
objGraphics.DrawString( strString, objFont, Brushes.White, , );
objBitmap.Save( Response.OutputStream, ImageFormat.Jpeg );
}
</Script>

最新文章

  1. JavaScript Array对象
  2. 多线程IP获取工具(C#)
  3. jQuery Ajax 实例 ($.ajax、$.post、$.get)
  4. 解决root用户ssh配置无密码登陆/hadoop用户照仿可以实现相同功能:hadoop用户登录并且把命令的所有root换成home/hadoop
  5. 一些ajax代码
  6. maya 专家模式
  7. js 随机星星 document.createElement(); setAttribute()
  8. Long-Short Memory Network(LSTM长短期记忆网络)
  9. GET请求中URL的最大长度限制总结
  10. [docker] 管理docker容器中的数据
  11. 多元线性回归(Linear Regression with multiple variables)与最小二乘(least squat)
  12. Enable-Migrations 在应用程序配置文件中找不到xx连接字符串
  13. linux下的gdb调试工具--断点调试
  14. 初学 Python(十四)——生成器
  15. python第三方库之PyGraphics
  16. Spring基于纯注解方式的使用
  17. mysql触发器:插入数据前更新创建时间为服务器的时间
  18. L219 China&#39;s office workers consider further education, training essential
  19. Html页面Dom对象之Event
  20. Linq to SharePoint与权限提升(转)

热门文章

  1. ext等待提示
  2. DeDe友情链接
  3. Python第三方库(模块)&quot;scikit learn&quot;以及其他库的安装
  4. JQuery调用iframe父页面元素与方法
  5. ZOJ1074 (最大和子矩阵 DP)
  6. python设计模式之装饰器模式
  7. PHP之路——MySql基础操作语句
  8. 禁用ios7 手势滑动返回功能
  9. Spring &lt;context:annotation-config/&gt;
  10. About Technology Research