编程语言

img dachuan999

NET中的动态生成图像组件 运行以后看不到图片,页面上什么都没有啊

发表于2004/10/31 12:00:00  416人阅读

123.aspx
<%@ Page Language="c#" ContentType="image/gif" Codebehind="14.aspx.cs" AutoEventWireup="false" %>
<%@ Import Namespace="stevenator.components" %>
<%@ OutputCache Duration="100" VaryByParam="none" %>
<script language="c#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HTTPImage myHTTPImage = new HTTPImage();
myHTTPImage.outputImageViaHTTP("/010.gif", this.Response, this.Server);
}
</script>


123.cs
namespace stevenator.components
 {
 using System;
 using System.IO;
 using System.Web;
 using System.Drawing;
 using System.Drawing.Imaging;
/// <summary>
/// Summary description for HTTPImage.
/// </summary>

 public class HTTPImage
 {
 public HTTPImage()
 {
 //
 // TODO: Add Constructor Logic here
 //
 }

 public void outputImageViaHTTP(string absolutePath, HttpResponse Response)
 {
 FileStream oFileStream;
 long lFileSize = 0;
 oFileStream = new FileStream(absolutePath, FileMode.Open);
 lFileSize = oFileStream.Length;

 byte[] bBuffer = new byte[(int)lFileSize];
 oFileStream.Read(bBuffer, 0, (int)lFileSize);
 oFileStream.Close();
 Response.ClearContent();
 Response.ContentType = "image/gif";
 Response.BinaryWrite(bBuffer);
 oFileStream.Close();
 Response.End();
 }

 public void outputImageViaHTTP(string virtualPath, HttpResponse Response, HttpServerUtility Server)

 {
 string path;
 path = Server.MapPath(virtualPath);
 outputImageViaHTTP(path, Response);
 }

}

}

阅读全文
0 0

相关文章推荐

img
取 消
img