主要请教如何在内存中生成图片和赋给网页传到客户机的浏览器上
谢谢

解决方案 »

  1.   

    建个网页
    <%@ Page language="c#" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title></title>
    <script runat="server">
    private string RndCode()
    {
    int code = (int)(new Random().NextDouble() * 10000);
    return code.ToString("0000");
    } private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    System.Drawing.Image image = new System.Drawing.Bitmap(45,20);
    System.Drawing.Graphics formGraphice = System.Drawing.Graphics.FromImage(image);
    string code = RndCode();
    System.Drawing.Font font = new System.Drawing.Font("Arial",12);
    System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
    formGraphice.Clear(System.Drawing.Color.White);
    System.Drawing.StringFormat format = new System.Drawing.StringFormat();
    formGraphice.DrawString(code,font,brush,0,00,format);
    font.Dispose();
    brush.Dispose();
    formGraphice.Dispose();
    image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    </script>
    <META http-equiv="Content-Type" content="image/jpeg">
    <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript (ECMAScript)" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <LINK href="Forum.css" type="text/css" rel="stylesheet">
    </HEAD>
    <body topMargin="0">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体"></FONT>
    </form>
    </body>
    </HTML>
      

  2.   

    System.Drawing空间是处理图片的
    用这个写到客户端:
    Response.BinaryWrite
      

  3.   

    谢谢: hzw66(超越理想)  我试下去