A Generic error occured in GDI+ in Image.Save() method

前端 未结 2 349
南笙
南笙 2021-01-26 17:10

I\'m trying to use this class but I\'m getting a Generic error occured in GDI+ in Image.Save() method. From what I read it\'s some stream I need to close but I don\'t know which

相关标签:
2条回答
  • 2021-01-26 17:45

    Unless your program is running as administrator you can not save directly to the root of C: make a folder and save it inside there instead.

    0 讨论(0)
  • 2021-01-26 17:53

    Have you tested saving the images in different locations?

    If it is still failing then without knowing exactly what is going on in your code I would hazard a guess to say that the original image is getting disposed somewhere before it should be. That's usually the most common cause of the error.

    I've written a library that handles many different imaging operations whilst ensuring that memory is correctly handled. It's well tested and very simple to use.

    You can get it here. http://imageprocessor.org/

    Example code using the library:

    using (ImageFactory imageFactory = new ImageFactory())
    {
        // Load, resize, set the quality and save an image.
        imageFactory.Load(@"C:\a.jpg")
                    .Resize(new Size(50, 100))
                    .Quality(90)
                    .Save(@"C:\myimage.jpeg);
    }
    
    0 讨论(0)
提交回复
热议问题