0
    protected void upload_Click(object sender, EventArgs e)
{  
    if (Upload.Value !="")
    {
        System.IO.Stream fs = Upload.PostedFile.InputStream;
        img_uploadStream = Upload.PostedFile.InputStream;
        System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
        Byte[] bytes = CreateThumbnail(br.ReadBytes((Int32)fs.Length),150);
        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
        imageField.Src = String.Format("data:{0};base64,{1}", "image/jpeg", base64String);
    }
}

上传图片后,Upload.PostedFile.InputStream 已设置为空值。我想将此输入流保存到 asp.net 视图状态以重用。

4

2 回答 2

0

您可以使用此代码

public Byte[] YourImage
{
get
{
if(ViewState["Key"] != null)
{
 return (Byte[]) ViewState["Key"];
}
return null;
}

set
{
  ViewState["Key"] = value;
}
}
于 2013-03-29T10:35:17.823 回答
0

在 upload_Click 中设置 ViewState:

ViewState["ImageStream"]=Upload.PostedFile.InputStream;

然后,您可以在要使用的页面中的任何位置获取视图状态:

System.IO.Stream fstream=(System.IO.Stream)ViewState["ImageStream"];
于 2013-03-29T10:37:58.667 回答