我想不用控件上载图片,以前没做过
不知道怎么用流读取和存储.jpg,.gif等格式的图片
高分求教~谢谢!!

解决方案 »

  1.   

    http://www.cnblogs.com/Hedonister/archive/2008/06/26/210913.html
      

  2.   

    1 使用BinaryReader
    2 使用Base64
      

  3.   

    Web程序,上传必须用控件,为什么最近都是希望不用控件来上传的? FileUpload控件或者html的input file都是一样,前者直接通过控件取文件流,后者通过Request.Files[]取流。或者你用ActiveX,比前者还麻烦的多。
    数据库里你用Image类型就可以存二进制数据,流可以很方便转为Byte[],塞进去就是了。
      

  4.   

    我这里有一段代码是从数据库读取二进制流的就是之前已经把图片以二进制流的形式存储到数据库中了现在把它从数据库中读出来希望对你有用。public partial class getPic : System.Web.UI.Page
    {
    protected void Page_Load(object sender, System.EventArgs e)
    {
    try
    {
                    PublicSqlClass pubClass = new PublicSqlClass();
                    
    string strPaperID = Page.Request.QueryString["PaperID"].ToString().Trim(); string stuID = strPaperID.Substring(1,12); string strSql="SELECT Pic FROM StudentInfoDetail WHERE StuID =" + "'" + stuID + "'"; SqlDataReader rd = pubClass.getDataReader(strSql); if(rd.Read())
    {
    //设定返回内容类型
    Response.ContentType="application/octet-stream"; Response.BinaryWrite((Byte[])rd["Pic"]); Response.End();
    }
    rd.Close();
    }
    catch(System.Exception ex)
    {
    throw ex;
    }
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    }
    #endregion
    }
      

  5.   

    可以从FileUpload中获得文件流..然后用System.Drawing.Imageing的Save方法保存到具体文件..
    Stream sm=FileUpload.PostFile.InputStream;
    img.Save()
      

  6.   


            Stream strmImage = this.FileUpload1.PostedFile.InputStream;
            int nLength = this.FileUpload1.PostedFile.ContentLength;
            byte[] bytImageContent = new byte[nLength];
            strmImage.Read(bytImageContent, 0, nLength);        System.Drawing.Image img = System.Drawing.Image.FromStream(strmImage);
            img.Save(Server.MapPath("~/") + this.FileUpload1.FileName);
            strmImage.Close();