我是 Webforms 的 MVC 新手,我正在尝试将图像上传到我的 Azure 存储容器。我已经根据需要上传图像并调整大小,但是某些图像上传的方向错误,例如它们以横向而不是纵向上传。
我已经用谷歌搜索了这个问题,但似乎找不到其他人遇到这个问题。
我必须上传的代码如下...
提前致谢
string accountName = "xxxxxxxxxxx";
string accountKey = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
try
{
if (file != null)
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer sampleContainer = client.GetContainerReference("uploadedimages");
sampleContainer.CreateIfNotExists();
CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(file.FileName);
using (Stream file1 = file.InputStream)
{
WebImage img = new WebImage(file.InputStream);
if (img.Width > 300)
img.Resize(300, 300);
byte[] bytes = img.GetBytes();
Stream stream = new MemoryStream(bytes);
blob.UploadFromStream(stream);
}
string userIdValue = getUserId();
if (ModelState.IsValid)
{
YourDayEntities6 context = new YourDayEntities6();
context.CreateDayByDate(model.DayDate, blob.Uri.ToString(), model.DayDesc, userIdValue);
}
}
}
catch (Exception e)
{
throw new Exception(string.Format("Error{0}", e.Message));
}
return RedirectToAction("GetAllDaysByDate");
最佳答案
大多数时候我看到这个问题不是由于存储造成的,Azure 存储会保存文件字节。
图像方向是 EXIF information 的一部分它包含在文件二进制中。
如果您使用客户端(JS)库管理上传,您可以查找其文档,看看 EXIF 信息是否被它删除或修改,有些库甚至有方法来更改它。
手机拍摄的图像存在一些问题,会报告错误的 EXIF 信息(横向而不是纵向,反之亦然),要解决此情况,您需要在上传之前处理 EXIF 信息。一些可能解决此问题的插件是 blueimp Javascript Load Image , ng-file-upload for AngularJS .
关于c# - MVC 图像上传 - 上传方向不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35975807/