asp.net输出 png 32位 图像,带透明alpha。
// pngtest.htm
<html>
<head></head>
<body bgColor="gray">
<img src="png.ashx" />
</body>
</html>
// png.ashx
<%@ WebHandler Language="C#" Class="Png" %>
using System.Web;
public class Png : IHttpHandler {
public void ProcessRequest (HttpContext context) {
HttpResponse Response = context.Response;
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(392, 72);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
g.Clear(System.Drawing.Color.Gray);
g.DrawString("This is 32bit png.", new System.Drawing.Font("verdana bold", 14f), System.Drawing.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;
}
}
}