c# - MVC 图像上传 - 上传方向不正确

标签 c# asp.net-mvc azure image-processing azure-blob-storage

我是 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/

相关文章:

c# - 如何在 docker 上的 rabbitmq 中发送消息?

Ajax Post : ASP. NET MVC 操作正在接收空对象

asp.net-mvc - 从 mvc 5 主页默认路由中删除主页索引

c# - 如何将 MVC 5 项目模板添加到 VS 2012?

azure - AWS 或 Azure 提供的虚拟机使用哪种 GPU?

azure - Istio Ingress 不起作用 - 仅端口转发起作用

c# - 使用 Roslyn 如何使用指令更新类?

c# - String.Format 计算预期参数的数量

Azure:将新文件添加到数据湖存储时运行数据工厂事件

c# - Entity Framework Core 创建和更新字段