Search code examples
.netmonoraspberry-pi2

System.Drawing.GDIPlus.CheckStatus System.Drawing.Image.FromFile System.ArgumentException [GDI+ status: InvalidParameter]


Actually on Raspberry PI 2. $ uname -a Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT Thu Feb 12 17:20:48 GMT 2015 armv7l GNU/Linux

$ mono --version Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4+rpi1)

getImageFromFile=images/complex/complex C3.jpg
loadOverlayImages plant life loadImages
getImageFromFile=images/butterfly/animated-butterfly-image-0004.gif
fn=images/butterfly/animated-butterfly-image-0004.gif  targetDir=images/butterfly  PlantImage.GetFrameCount=5 for file:images/butterfly/animated-butterfly-image-0004.gif
getImageFromFile=images/butterfly/animated-butterfly-image-0005.gif
ERROR: getImageFromFile- System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0
  at System.Drawing.Image.FromFile (System.String filename, Boolean useEmbeddedColorManagement) [0x00000] in <filename unknown>:0
  at System.Drawing.Image.FromFile (System.String filename) [0x00000] in <filename unknown>:0
  at PlantLifeAnimationForm.PlantLifeImagesService.getImageFromFile (System.String filePath) [0x00015] in     /home/pi/emgucv/PlantLifeAnimation/PlantLifeAnimationForm/model/PlantLifeImagesService.cs:223
fn=images/butterfly/animated-butterfly-image-0005.gif  targetDir=images/butterfly
Unhandled Exception:

enter image description here

This file works fine on windows (DIES HERE: System.Drawing.Image.FromFile(filePath)

            using (Bitmap temp = (Bitmap)System.Drawing.Image.FromFile(filePath))
            {
                bitmapSource = (Bitmap)temp.Clone();
            }

Solution

  • See this mono bug - https://bugzilla.novell.com/show_bug.cgi?id=510805. Basically what they say is problem like yours happens when libgif cannot handle provided gif. For example, for your image gifinfo (which is part of libgif-tools package) says:

    Image 8 is not confined to screen dimension, aborted.

    I must also warn you that if you do any serious image processing on mono - avoid using standard Bitmap and related classes, they are buggy in many many ways (from my own fresh experience). For most image manipulations I use MagickWand C api directly (via p-invoke).