Imageprocessor: Invalid parameter when trying to load large image

Created on 5 Jan 2017  路  13Comments  路  Source: JimBobSquarePants/ImageProcessor

I have hit the limit of image sizes for GDI+ so I was looking for an alternative and came across your library. Unfortunately it seems it does not like large images either. I have a PNG that is 17MB in size that I need to be able to manipulate. I get an "Invalid Parameter" error when trying to load it. Any ideas? Here is the stack trace:

System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at ImageProcessor.Common.Extensions.ImageExtensions.Copy(Image source, AnimationProcessMode animationProcessMode, PixelFormat format, Boolean preserveExifData)
at ImageProcessor.ImageFactory.Load(Stream stream)
at GLHOMES.MultiTouch.Converter.Program.Main(String[] args) in C:\Development\Proofs\Multi Touch\Converter\Program.cs:line 39

Most helpful comment

For others who hit a similar issue:
I had this when running on IISExpress in visual studio which runs the 32bit version by default.
To find the setting for 64 bit version go to:
tools -> options -> Projects and Solutions -> Web Projects (or similar depending on version of visual studio)

All 13 comments

It looks like you are still running into the limits of System.Drawing. Have you tried ImageSharp: https://github.com/JimBobSquarePants/ImageSharp. This is the .NET Core version of this library that does not use System.Drawing.

I just did. It runs into an OutOfMemoryException for that same file.

Then it looks like you've hit the physical limitation of your machine. Are you running in 32 or 64bit mode? Does the image require transparency?

Probably. Its a png with transparency, and I am running it in a 64 bit console app on Windows 7 with 32GB of memory. I am sure once its unpacked its several gb's of data in memory that .net chokes on.

You might want to give my library a try: https://github.com/dlemstra/Magick.NET. This library has support for reading ridiculous large images. It moves the memory to disk when it runs out of memory. Might eat up a big part of your drive though.

That was next on my list to try. Thanks!

Agreed. Give that a go.

17MB in compressed form must be massive image dimension-wise. I dunno if I'll ever add file based paging to support files that big in ImageSharp but food for thought.

Yeah, its huge because its for a mapping application and has to be very high resolution. We are trying to use that file to create tiles at lower resolutions for map systems like google and bing. There are commercial products that I can use to do that but they are incredibly expensive. Many posts I found recommend looking into memory mapped files, but that doesn't give me much help in resizing and chopping up the image into tiles.

I would have though svg would be your best bet for mapping. scalable and tiny.

I wish that were the case. Our drawings are so complex from CAD that converting them to any vector format does not perform well once displayed in any technology we have tried. We hit the limit of what it can do. We are now trying rasterized formats instead since there is ever only a set of fixed size tiles loaded into memory at a time. Its generating the tiles at high enough resolution that is the issue.

There's not really much I can offer here I'm afraid. I wasn't aware of performance rendering issues with SVG.

If Magick.NET doesn't work I'm not sure what to suggest.

For others who hit a similar issue:
I had this when running on IISExpress in visual studio which runs the 32bit version by default.
To find the setting for 64 bit version go to:
tools -> options -> Projects and Solutions -> Web Projects (or similar depending on version of visual studio)

@Myster Yeah that one catches lots of people out. My advice is generally use IIS.

Was this page helpful?
0 / 5 - 0 ratings