如何写一段C#代码,实现下面的VB的功能。
具体来说就是在后台写段代码,将已有的图片流显示在网页上
<%@ page language="vb" contenttype="image/jpeg" %> 
 <%@ import namespace="system.drawing" %> 
 <%@ import namespace="system.drawing.imaging" %> 
 <%@ import namespace="system.drawing.drawing2d" %> 
  
 <% 
 ''''清空Response 
 response.clear 
  
 ''''建立一个120*30大小,24bit的BMP图象; 
 dim imgOutput as New bitmap(120, 30, pixelformat.format24bpprgb) 
  
 ''''根据以上BMP建立一个新图象; 
 dim g as graphics = graphics.fromimage(imgOutput) 
  
 g.clear(color.Green) 
 g.smoothingMode = smoothingMode.antiAlias 
  
 g.drawString("看见了吗?", New font("黑体",16,fontstyle.bold),new SolidBrush(Color.White),New pointF(2,4)) 
  
 g.FillRectangle(New linearGradientBrush(New point(0,0), New point(120,30), color.fromArgb(0,0,0,0),color.fromArgb(255,255,255,255)),0,0,120,30) 
  
 imgOutput.save(response.outputstream, imageformat.jpeg) 
  
 g.dispose() 
 imgOutput.dispose() 
 response.end 
 %>  

解决方案 »

  1.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Clear(); Bitmap imgOutput = new Bitmap( 120, 30, PixelFormat.Format24bppRgb);
    Graphics g = Graphics.FromImage( imgOutput );
    g.Clear( Color.Green );
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g.DrawString( "看见了吗?", new Font( "黑体", 16, FontStyle.Bold ),new SolidBrush( Color.White ), new PointF(2,4) );
    g.FillRectangle( new LinearGradientBrush(new Point(0,0),new Point(120,30),Color.FromArgb(0,0,0,0),Color.FromArgb(255,255,255,255)),0,0,120,30);
    imgOutput.Save( Response.OutputStream, ImageFormat.Jpeg );
    g.Dispose();
    imgOutput.Dispose();
    Response.End();
    }
      

  2.   

    你新建一个web项目,在它的一个页面上按上面的代码改page_load然后把using改成如下:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;然后运行那个页面就行了我试过了,可以的
      

  3.   

    to 楼上dayasky(.Neting) 
    我这样为什么显示不出图形
    private void Button2_Click(object sender, System.EventArgs e)
    {
    string url="http://localhost/img/post.JPG";


    System.IO.Stream  stream=DownloadFile(url);
    Bitmap output=new Bitmap(120,30,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    Graphics g = Graphics.FromImage(output);
    g.FillRectangle(new LinearGradientBrush(new Point(0,0),new Point(120,30),Color.FromArgb(0,0,0,0),Color.FromArgb(255,255,255,255)),0,0,120,30);
    try
    {
    output.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    catch
    {}
    finally
    {
    g.Dispose();
    output.Dispose();
    }

    } public Stream DownloadFile(string FileURL)
    {

    HttpWebRequest r=HttpWebRequest.Create(FileURL) as HttpWebRequest;

    r.AllowAutoRedirect=true;
    HttpWebResponse res=r.GetResponse() as HttpWebResponse;
    System.IO.Stream stream=res.GetResponseStream();
    return stream;
    }
      

  4.   

    你先前的vb.net代码是用这样的方式把图像流显示出来的:
    imgOutput.Save( Response.OutputStream, ImageFormat.Jpeg );不知道你的DownloadFile(string FileURL) 有什么用如果只想显示
    把output.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
    改成output.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
    就好了
      

  5.   

    参看
    http://blog.csdn.net/knight94/archive/2006/03/31/645987.aspx
      

  6.   

    还是不行
    DownloadFile(string FileURL) 是从一个链接下载一张图片,最后以System.IO.Stream返回。
      

  7.   

    to DownloadFile(string FileURL) 是从一个链接下载一张图片,最后以System.IO.Stream返回。你下载的文件是存在本地吗,如果是的话,那么可以如下:
    FileStream stream new FileStream( yourImageFile, 
    FileMode.Open, 
    FileAccess.Read);// Create a buffer to hold the stream bytes
    byte[] bData = new byte[stream.Length];

    // Read the bytes from this stream
    stream.Read(bData, 0, (int)stream.Length);
    stream.Close();来替换我上面给的例子中
      

  8.   

    to 楼上
    我来从新解释一下我的要求,
    我想点击一下按钮,将一个链接上的图片下载过来,然后在自己的页面显示出来。图片不想存在本地,哪位高人能用C#给我写段代码吗?
      

  9.   

    to 我想点击一下按钮,将一个链接上的图片下载过来,然后在自己的页面显示出来。图片不想存在本地,哪位高人能用C#给我写段代码吗?那你根本不用下载了,直接把图片的链接赋给显示容器的imageurl即可