asp.net输出32位png图像

asp.net输出 png 32位 图像,带透明alpha。
// pngtest.htm
<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(39272);

    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;}}
}

 


posted @ 2009-12-05 16:46  coudly  阅读(567)  评论(0编辑  收藏  举报