none
ASP.NET 获取图片 RRS feed

答案

  • 如何将Byte64,Bitmap,Image这三种类型给ASP.NET中的Image1控件,并让其显示


    应该不可行(就算行也绕远路了)
    ASP.net Image控件只能指定ImageUrl图片路径,并不像WinForm的PictureBox控件可以指定Image实例

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image(v=VS.100).aspx
    http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.aspx

    所以要动态显示图片,大概用以下做法
    Default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    </head>
    
    <body>
     <form id="form1" runat="server">
    
      <asp:Image ID="Image1" ImageUrl="getImage.aspx?uid=1" runat="server" />
      <asp:Image ID="Image2" ImageUrl="getImage.aspx?uid=2" runat="server" />
    
     </form>
    </body>
    </html>
    

    getImage.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    
    public partial class getImage : System.Web.UI.Page
    {
    
     protected void Page_Load(object sender, EventArgs e)
     {
    
      if (!string.IsNullOrEmpty(Request.QueryString["uid"]))
       {
    
         Response.Clear();
         Response.ContentType = "image/jpeg";
         Response.WriteFile(Server.MapPath("~/images/" + Request.QueryString["uid"] + ".jpg"));
    
       }
    
     } 
    
    
    }
     

    Shadowと愉快なコード達
    Please correct me if my concept is wrong
    2011年7月15日 12:38

全部回复