标签: imageresizer

ImageResizer配置提供了Image引用

我们正在使用来自imageresizing.net的图像缩放器,并且看到了一些奇怪的行为.

当我们从流中读取图像然后调整图像大小时,我们无法再访问原始图像的属性.

以下代码将重现该问题.

 static void Main(string[] args)
        {
            using(var httpPostedFileBaseImage = new FileStream(@"C:\test.jpg",FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using(var uploadedImage = Image.FromStream(httpPostedFileBaseImage))
                {

                    Console.WriteLine(uploadedImage.Width);
                    var resizedImage = ImageBuilder.Current.Build(uploadedImage,
                                                                  new ResizeSettings("width=110;height=83"));

                    Console.WriteLine(uploadedImage.Width);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

在ImageBuilder行之前,我们可以看到uploadedImage.Width很好,但之后会抛出异常:

System.ArgumentException was unhandled
  HResult=-2147024809
  Message=Parameter is not valid.
  Source=System.Drawing
  StackTrace:
       at System.Drawing.Image.get_Width()
       at ConsoleApplication6.Program.Main(String[] args) in C:\Users\Daniel\Desktop\ConsoleApplication6\ConsoleApplication6\Program.cs:line 25
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, …
Run Code Online (Sandbox Code Playgroud)

.net image-processing imageresizer

5
推荐指数
1
解决办法
689
查看次数

将图像转换为流

我正在使用一个上传图像,获取流并使用imageresizer.net调整大小的函数,然后将流上传到Amazon S3.

现在我想拍一张本地照片并将其转换为流.(调整大小并上传到amazonS3).基本上,如何将图像转换为流.

这可能是一个简单的问题,无法在任何地方找到答案.

这是一些基本代码.

Public Shared Sub MoveToAmazon(strImg As String, SKU As String)
        Dim fullImg As String = "C:\ImageLocation\" & strImg
        Dim img As Image = Image.FromFile(fullImg)

        'Here Im missing the code to convert it to a stream.
        UploadImage(imgStream, SKU)  

End Sub


Public Shared Sub UploadImage(imgStream As Stream, imgName As String)

    Dim MainStream As Stream = New MemoryStream
    Dim HomeStream As Stream = New MemoryStream
    Dim SmallStream As Stream = New MemoryStream
    Dim TinyStream As Stream = New MemoryStream …
Run Code Online (Sandbox Code Playgroud)

asp.net image amazon-s3 image-resizing imageresizer

4
推荐指数
1
解决办法
3981
查看次数

使用MVC2动态调整SQL数据库的大小

我有一个简单的MVC2应用程序,它将文件从浏览器上传到MS SQL数据库作为图像blob.

然后我可以用以下结果返回结果:

        public FileContentResult ShowPhoto(int id)
        {
           TemporaryImageUpload tempImageUpload = new TemporaryImageUpload();
           tempImageUpload = _service.GetImageData(id) ?? null;
           if (tempImageUpload != null)
           {
              byte[] byteArray = tempImageUpload.TempImageData;
              return new FileContentResult (temp, "image/jpeg");
           }
           return null;
        }
Run Code Online (Sandbox Code Playgroud)

但是我希望将这些图像重新调整为缩略图和图库大小的视图.这个结果可以做到这一点吗?我一直在玩伟大的imageresizer.net,但似乎想要将图像存储在我想要避免的服务器上.有可能在飞行中这样做吗?

我需要保留原始文件,如果可能的话,不要将图像存储为服务器上的文件.

感谢您的任何指示!

c# sql image-scaling asp.net-mvc-2 imageresizer

4
推荐指数
1
解决办法
2831
查看次数

MVC4项目和ImageResizer

问题:在任何页面访问中使用ImageResizer的MVC 4测试应用程序响应"无法加载类型'ImageResizer.InterceptModule'"

为了测试和理解ImageResizer如何工作,在VS 2012中创建了MVC4项目,创建了一个单独的控制器来显示HelloWorld页面.按预期工作.

下一步是从NuGet添加ImageResizer.安装了用于MVC的ImageResizer Web.Config安装.这个包添加了三个额外的包:

ImageResizer Web.Config安装ImageResizer.MVC - MVC友好的实用工具ImageResizer

尝试运行应用程序会导致黄色死亡屏幕显示"无法加载类型'ImageResizer.InterceptModule."

尝试解决但没有成功包括:

  1. 验证DLL存在.
  2. 删除并重新安装软件包.
  3. 从工作的webforms应用程序复制ImageResizer dll
  4. ImageResizer故障排除指南中的第1项似乎不是问题"1.您的网站内部有一个'子站点'(应用程序文件夹).应用程序文件夹从其父站点继承所有Web.config设置,但期望拥有自己/ bin文件夹中这些设置引用的所有dll的副本.您可以通过以下方法解决此问题:(a)将app文件夹更改为虚拟文件夹,(b)将ImageResizer.dll和插件的副本添加到该应用程序中的/ bin文件夹也是,或者(c)使用子Web.config中的语句从父Web.config中取消继承的语句.选项(c)将禁用子应用程序中的图像大小调整."

是的,views目录中有一个web.config文件.尝试在视图中创建和复制图像缩放器dll到bin目录 - 没有成功.尝试在views目录中的web.config中添加一个删除.再没有成功.

asp.net-mvc-4 imageresizer

4
推荐指数
1
解决办法
1748
查看次数

ImageResizer 错误

我正在使用 Image Resizer imageresizing.net。但是,当我尝试上传或调整图像大小时,会发生错误:

源流在最后(你已经读过了吗?)。你必须调用 stream.Seek(0, SeekOrigin.Begin); 在重新使用流之前,或者在第一次读取流时使用带有 ResetSourceStream=true 的 ImageJob。

using (Stream newFile =  System.IO.File.Create(Path.Combine(_pathResolver.ResolvePath(_appSettings.CompanyLogosDirectory), newFileName)) )
{
     //newFile.Seek(0, SeekOrigin.Begin);

     ImageResizer.ImageJob i = new ImageJob();
     //i.ResetSourceStream = true;
     i = new ImageResizer.ImageJob(logo.InputStream, newFile, new ImageResizer.ResizeSettings("width=120;height=45;format=jpg;mode=max"));

     i.CreateParentDirectory = false; //Auto-create the uploads directory.
     i.Build();
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc image imageresizer

4
推荐指数
1
解决办法
1351
查看次数

ImageResizer:你如何使用说明?

ResizeSettings的文档说:"由Instructions类替换" http://documentation.imageresizing.net/docu/ImageResizer/ResizeSettings.htm

指令文档说:"ResizeSettings的继承者." http://documentation.imageresizing.net/docu/ImageResizer/Instructions.htm

但是,我无法弄清楚如何使用Instructions而不是ResizeSettings.我试过了

  • 谷歌
  • 文档(documentation.imageresizing.net)
  • 浏览对象浏览器以获取指令的使用
  • 在.net Reflector中搜索ImageResizer.dll以获取指令的使用
  • 反编译所有ImageResizer.dll并搜索生成的代码.

如果说明取代了ResizeSettings,那么我该如何使用它而不是ResizeSettings?

===编辑 - 更多细节:

这是一种使用ResizeSettings的方法:

    public static Bitmap Resize(Bitmap bitmap, int maxHeight, int maxWidth)
    {
        var setting = new ResizeSettings
        {
            MaxHeight = maxHeight,
            MaxWidth = maxWidth,
        };

        return ImageBuilder.Current.Build(bitmap, setting);
    }
Run Code Online (Sandbox Code Playgroud)

阅读说明是ResizeSettings的替代品,我尝试的第一件事就是:(我希望ImageBuilder可能有一个重载的Build方法)

    public static Bitmap Resize(Bitmap bitmap, int maxHeight, int maxWidth)
    {
        var instructions = new Instructions
        {
            Width = maxWidth,
            Height = maxHeight,
            Mode = FitMode.Max
        };

        return ImageBuilder.Current.Build(bitmap, instructions);
    }
Run Code Online (Sandbox Code Playgroud)

imageresizer

4
推荐指数
1
解决办法
2029
查看次数

使用 ImageResizer 调整大图像和内存不足异常

当我使用 ImageResizer.Net(在 32 位系统上)调整 9000x9000 平方的图像时遇到内存不足异常:

ImageBuilder.Current.Build(imageFileName, outputFileName, settings, true);
Run Code Online (Sandbox Code Playgroud)

不过,我能够使用流成功调整大图像的大小:

using (var stream = new FileStream(imageFileName, FileMode.Open, FileAccess.Read))
using (var img = Image.FromStream(stream, true, false))
{
    ImageBuilder.Current.Build(img, outputFileName, settings);
    stream.Close();
}
Run Code Online (Sandbox Code Playgroud)

但是,最后一个方法在 x 循环后仍然会遇到内存不足异常。ImageResizer 中是否存在巨大的内存泄漏,或者我的代码中是否存在错误?

无论哪种方式,有解决方法吗?

c# imageresizer

4
推荐指数
1
解决办法
3099
查看次数

使用AzureReader2插件的Azure的ImageResizer不能调整大小

编辑

我可以使用它,但是必须添加RemoteReader插件。当我从项目中删除AzureReader2插件时,它仍然可以工作,这很有意义,但是AzureReader2插件对我有什么好处?

原始问题

我已经完成了此处概述的所有操作(包括注释),但似乎无法弄清楚为什么我不能使用此用于imageresizer的插件即时调整图像大小。

这是我在元素下的web.config条目的样子:

<add name="AzureReader2" prefix="~/img/" connectionString="DefaultEndpointsProtocol=https;AccountName=[Account];AccountKey=[key]" endpoint="http://<account>.blob.core.windows.net/" />
Run Code Online (Sandbox Code Playgroud)

并且我将我的容器设置为“ img”。

当我转到该URL进行测试时: https://<account>.blob.core.windows.net/img/image.jpg?width=50该图像显示出来,但只是其正常大小。我也尝试在本地和实时AWS上运行此命令,但仍然无法调整大小:(

c# asp.net-mvc azure asp.net-mvc-4 imageresizer

3
推荐指数
1
解决办法
1658
查看次数

Imageresizer.AzureReader2不适用于最新的Azure SDK 2.1.0.3

我有一个ASP.NET MVC 5应用程序,我已升级到最新的SDK 2.1.0.3,似乎ImageResizer已经爆炸了.有没有工作?这是详细信息:

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.WindowsAzure.Storage, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = xxx
LOG: Initial PrivatePath = xxx
Calling assembly : ImageResizer.Plugins.AzureReader2, Version=3.4.0.763, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: x
LOG: Using host configuration file: x
LOG: Using machine configuration file from x
LOG: Post-policy reference: Microsoft.WindowsAzure.Storage, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/6038b9fb/8488b4a1/Microsoft.WindowsAzure.Storage.DLL.
LOG: Attempting download …
Run Code Online (Sandbox Code Playgroud)

c# azure imageresizer

3
推荐指数
1
解决办法
1285
查看次数

刚刚通过NuGet更新了ImageResizer,无法运行app,因为它无法找到BundleAttribute

我只是想更新Azure存储,但这样做意味着我需要更新ImageResizer AzureReader和更新应用使用的.Net 4.5.2(Azure的网站设置为.NET 4.6).现在我已经掌握了最新版本的所有内容; 我已经清理并重建了应用程序.它在本地工作正常,但当我将其发布到Azure时,我收到以下错误.我无法加载诊断页面.

Server Error in '/' Application.

Could not load type 'ImageResizer.Util.BundleAttribute' from assembly 'ImageResizer, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeLoadException: Could not load type 'ImageResizer.Util.BundleAttribute' from assembly 'ImageResizer, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.

Source Error: 

An unhandled exception was generated during the execution of the current web …
Run Code Online (Sandbox Code Playgroud)

.net azure imageresizer azure-web-sites

3
推荐指数
1
解决办法
736
查看次数