.ashx中生成图片怎么保存到文件夹中?
怎么能将生成的图片保存一个指定的路径? --------------------编程问答--------------------
--------------------编程问答-------------------- bmp.Save("D:/" + "sa.bmp", System.Drawing.Imaging.ImageFormat.Jpeg);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
namespace Web
{
/// <summary>
/// Handler1 的摘要说明
/// </summary>
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
System.Drawing.Bitmap image = new System.Drawing.Bitmap(300, 300);
Graphics g = Graphics.FromImage(image);
try
{
Font font = new System.Drawing.Font("Verdana", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString("123456", font, brush, 2, 2);
image.Save(context.Server.MapPath("~")+"\\1.jpg");
}
finally
{
g.Dispose();
image.Dispose();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
经测试成功的。 --------------------编程问答--------------------
+1
补充:.NET技术 , ASP.NET