fschultz / NetImageLibrary

Library to help with image handling such as resizing, cropping, applying filters (brightess, contrast, unsharpen mask, chroma key etc), watermarking, thumbnail creation, opening/saving files or streams and more.
http://kaliko.com/image-library/
Other
90 stars 27 forks source link

I get a "Common Error in GDI+" when saving an image with Kaliko SaveJPG. #15

Open hannibalstgt opened 7 years ago

hannibalstgt commented 7 years ago

Hello Fredrik, you can probably remember me, the person which coded the CineStripScanner probably one of the very first users of the the Kaliko Image Library FastFilters to apply Unsharpmask to scanned Cine Film Strips.

I am now doing a new program (CineFrameGrabber) a program that should grab frames of a Cine Film (Super 8 or Normal 8) using a Digital Microscope and a stepper motor to advance the frames. This creates some problems in synchronizing the various devices (the videocapture Device, the Serial Port with the stepper motor and my program ). Therefore I have to use the TPL because I have to wait for the completion events of these devices.

But I do have a problem when saving images with Kaliko (under Windows 10 Home Edition 64 Bit Creators Edition). I am using VS Community 2017 .NET 4.5 and C# .

This is the code snippet I created

..... using Kaliko.ImageLibrary; using Kaliko.ImageLibrary.FastFilters; using Kaliko.ImageLibrary.Filters; using System.Drawing.Imaging; ....

.... if (snapshotSelected) { captureFrame.Snapshot(); } else { requestImage = true; } taskG = new Task(new Action(showAndSaveImage)); taskG.Start(); taskG.Wait(); ....... ......

    public static void showAndSaveImage()
    {
        KalikoImage theGrabbed;   // the grabbed cine film image
        int    imageNrI = ExecutionForm.actImgNo;
        String targetFile;
        string imageNrS;
        string fillZeros = "000000";
        int nrLen = 0;
        string imgType = DefinitionForm.activeInstance._imageType;  // JPG or PNG

/line 250/ Console.WriteLine("0250 showAndSaveImage started"); try { if (ExecutionForm.snapshotSelected == true) { ExecutionForm.picBoxImage = (Image)new Bitmap(ExecutionForm.aSnapshotFrame, ExecutionForm.picBoxSize); theGrabbed = new KalikoImage(ExecutionForm.aSnapshotFrame); } else { ExecutionForm.picBoxImage = (Image)new Bitmap(ExecutionForm.aVideoFrame, ExecutionForm.picBoxSize); theGrabbed = new KalikoImage(ExecutionForm.aVideoFrame); ; } if (theGrabbed != null) { if (DefinitionForm.activeInstance._sharpenOn == true) { Kaliko.ImageLibrary.FastFilters.FastUnsharpMaskFilter unsharpMaskFilter = new Kaliko.ImageLibrary.FastFilters.FastUnsharpMaskFilter(DefinitionForm.activeInstance._radiusF, DefinitionForm.activeInstance._contrastF, DefinitionForm.activeInstance._thresholdI); theGrabbed.ApplyFilter(unsharpMaskFilter); }

                imageNrS = fillZeros + Convert.ToString(imageNrI).Trim();
                nrLen = imageNrS.Length;
                imageNrS = imageNrS.Substring((nrLen - 6), 6);
                ExecutionForm.actImgNoS = DefinitionForm.activeInstance._actProjectId +  DefinitionForm.activeInstance._subDirName + imageNrS + "." + DefinitionForm.activeInstance._imageType;
                targetFile = DefinitionForm.activeInstance._actTargetSubFolder + actImgNoS;
                switch (imgType)
                {
                    case "JPG":

/line 309/ theGrabbed.SaveJpg(targetFile, 90); // Common GDI+ error break; case "PNG": theGrabbed.SavePng(targetFile); break; default: theGrabbed.SavePng(targetFile); break; } ExecutionForm.theRetVal = true; } else { ExecutionForm.theRetVal = false; } } catch (Exception ex) { ExecutionForm.theRetVal = false; Console.WriteLine("315 ex = " + ex); } }


And that is what I get. ( Always returnValue = false; !!! due to the Exception occured) . What am I doing wrong. What is a common GDI+ error. I do nothing special except using the Task Parallel Library (TPL) of MS .NET 4.5

This is the output of System.WriteLine: ExecutionForm.txt

0250 showAndSaveImage started "CineFrameGrabber.exe" (CLR v4.0.30319: CineFrameGrabber.exe): "C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing.resources\v4.0_4.0.0.0_de_b03f5f7f11d50a3a\System.Drawing.resources.dll" geladen. Das Modul wurde ohne Symbole erstellt. Ausnahme ausgelöst: "System.Runtime.InteropServices.ExternalException" in System.Drawing.dll 315 ex = System.Runtime.InteropServices.ExternalException (0x80004005): Allgemeiner Fehler in GDI+. bei System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) bei Kaliko.ImageLibrary.ImageOutput.SaveFile(KalikoImage image, String fileName, Int64 quality, String imageFormat, Boolean saveResolution) bei Kaliko.ImageLibrary.KalikoImage.SaveJpg(String fileName, Int64 quality) bei CineFrameGrabber.ExecutionForm.showAndSaveImage() in D:\C#Prog\Projects\CineFrameGrabber\CineFrameGrabber\ExecutionForm.cs:Zeile 309.

Many Thanks for your assistance Wolfgang Kurz wolfgang@uwkurz.de

The full method is atached as txt File. ExecutionForm.txt (rename it to .cs if needed)

fschultz commented 7 years ago

Hi Wolfgang, Nice to hear from you again. I haven't seen this error before, but I hope that we can get it solved as soon as possible. As the exception seems to be thrown from within System.Drawing my initial thought is if it could be memory related. What image size do you have when this error occurs and does it occur using any other save function (such as the one for PNG)? I'll look into this to see if I either can reproduce the problem or find some information about this specific (but yet generic) error message.

Best regards, Fredrik