代码一:context.Response.ContentType = "text/JPEG";
string fullpath = context.Server.MapPath("a.jpg");
string name = context.Request["Name"]; using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fullpath))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
g.DrawString(name, new System.Drawing.Font("雅黑", 36), System.Drawing.Brushes.Red, 50, 70);
}
bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
代码二:context.Response.ContentType = "text/JPEG";
string fullpath = context.Server.MapPath("a.jpg");
string name= context.Request["Name"];
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fullpath);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.DrawString(name, new System.Drawing.Font("雅黑", 36), System.Drawing.Brushes.Red, 50, 70); bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
二段代码中的实现的功能都一样,为什么第一段中要用using包起来。使用using 与不使用using的区别在哪里?
string fullpath = context.Server.MapPath("a.jpg");
string name = context.Request["Name"]; using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fullpath))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
g.DrawString(name, new System.Drawing.Font("雅黑", 36), System.Drawing.Brushes.Red, 50, 70);
}
bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
代码二:context.Response.ContentType = "text/JPEG";
string fullpath = context.Server.MapPath("a.jpg");
string name= context.Request["Name"];
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fullpath);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.DrawString(name, new System.Drawing.Font("雅黑", 36), System.Drawing.Brushes.Red, 50, 70); bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
二段代码中的实现的功能都一样,为什么第一段中要用using包起来。使用using 与不使用using的区别在哪里?
解决方案 »
- asp.net 选择文件夹,上传文件夹下面的所有图片
- html5与silverlight的优缺点
- updatePanle做更新时如何只显示一个updateProgress的内容?
- 谁有(whios)的域名查询代码,急求一份!多谢!
- 我做的网站,随着功能的添加和修改,耦合度越来越高了.
- dataTable.Rows.InsertAt(drow, i);该行已经属于另一个表
- 如何给LinkButton等服务器控件加上JQuery应用
- 复合控件如何得到子控件生成的HTML代码
- datalist ItemTemplate中checkbox的问题
- 请问*.htc文件是做什么的阿
- c#webbrowser为页面嵌入一段JS,并执行JS
- asp.net中如何从一段字符串当中获取图片路径
// 使用对象
}
//对象资源被释放
大括号完毕释放