System.Drawing.Image.FromStream参数无效
本文关键字:参数 无效 FromStream Image Drawing System | 更新日期: 2023-09-27 18:13:24
我试图从数据库中获取blob,但有时我得到错误"无效参数"
System.Drawing.Image objimg = System.Drawing.Image.FromStream(blobstream, true);
下面是我的代码:
public partial class showblob : System.Web.UI.Page
{
private System.Drawing.Image.GetThumbnailImageAbort delegateabort;
protected void Page_Load(object sender, EventArgs e)
{
// Get a handle on account, create a blob service client and get container proxy
var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
account.CreateCloudTableClient().CreateTableIfNotExist("tablename");
var client = account.CreateCloudBlobClient();
CloudBlobContainer container = client.GetContainerReference("tablename");
string id = Request["id"].ToString();
// Retrieve reference to a blob named "myblob"
CloudBlob blob = container.GetBlobReference(id);
BlobStream blobstream = blob.OpenRead();
if (Request["imgvd"] == "0")
{
Response.ContentType = "image/jpeg";
System.Drawing.Image objimg = System.Drawing.Image.FromStream(blobstream, true);
if (Request["thumb"] != null)
objimg = objimg.GetThumbnailImage(140, 210, delegateabort, System.IntPtr.Zero);
objimg.Save(Response.OutputStream, ImageFormat.Jpeg);
}
并存储图像因为我已经使用这个方法添加了:
if (fileFoto.HasFile)
try
{
CloudBlobClient blobClient = account.CreateCloudBlobClient();
// Retrieve a reference to a container
CloudBlobContainer container = blobClient.GetContainerReference("tablename");
// Create the container if it doesn't already exist
container.CreateIfNotExist();
CloudBlob blob = container.GetBlobReference("c" + ViewState["id"].ToString());
blob.UploadFromStream(fileFoto.PostedFile.InputStream);
}
我的问题解决了。问题是我将引用设置为
CloudBlob blob = container.GetBlobReference("c" + ViewState["id"].ToString());
当我上传照片并使用
拍摄时CloudBlob blob = container.GetBlobReference(ViewState["id"].ToString());