asp.net输出32位png图像
asp.net输出 png 32位 图像,带透明alpha。
// pngtest.htm
// pngtest.htm
<html>
<head></head>
<body bgColor="gray">
<img src="png.ashx" />
</body>
</html>
<head></head>
<body bgColor="gray">
<img src="png.ashx" />
</body>
</html>
// png.ashx
using System.Web;
using System.Drawing;
public class Png : IHttpHandler {
public void ProcessRequest (HttpContext context) {
HttpResponse Response = context.Response;
Bitmap bmp = new Bitmap(392, 72);
Graphics g = Graphics.FromImage(bmp);
g.Clear(System.Drawing.Color.Gray);
g.DrawString("This is 32bit png.",
new Font("verdana bold", 14f),
Brushes.HotPink, 0f, 0f);
g.Dispose();
bmp.MakeTransparent(System.Drawing.Color.Gray);
System.IO.MemoryStream MemStream = new System.IO.MemoryStream();
bmp.Save(MemStream, System.Drawing.Imaging.ImageFormat.Png);
bmp.Dispose();
Response.Clear();
Response.ContentType = "image/PNG";
MemStream.WriteTo(Response.OutputStream);
MemStream.Close();
}
public bool IsReusable {get {return false;}}
}
using System.Drawing;
public class Png : IHttpHandler {
public void ProcessRequest (HttpContext context) {
HttpResponse Response = context.Response;
Bitmap bmp = new Bitmap(392, 72);
Graphics g = Graphics.FromImage(bmp);
g.Clear(System.Drawing.Color.Gray);
g.DrawString("This is 32bit png.",
new Font("verdana bold", 14f),
Brushes.HotPink, 0f, 0f);
g.Dispose();
bmp.MakeTransparent(System.Drawing.Color.Gray);
System.IO.MemoryStream MemStream = new System.IO.MemoryStream();
bmp.Save(MemStream, System.Drawing.Imaging.ImageFormat.Png);
bmp.Dispose();
Response.Clear();
Response.ContentType = "image/PNG";
MemStream.WriteTo(Response.OutputStream);
MemStream.Close();
}
public bool IsReusable {get {return false;}}
}