A generic error occurred in GDI+

偶尔善良 提交于 2020-01-15 03:43:11

问题


A generic error occurred in GDI+

[ExternalException (0x80004005): A generic error occurred in GDI+.] System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) +615257

I have a webpage in which a pdf is converted to png, and using the response.outputstream it is displayed. when i run this on my local machine is works fine. but when i run the same code on server is throws this exception.

my question is , where i could look in for error. as there is no inner exception or any other information provided. only clue is that it's happening on Image.Save , but the same code works perfectly fine on my local machine , then y is it not working on production???

http://blog.maartenballiauw.be/post/2008/05/13/ASPNET-MVC-custom-ActionResult.aspx

this is the example i am following


回答1:


Take a look at the big "Caution" note in the System.Drawing documentation. All kinds of weird stuff can happen when you use something intended for desktop processing in a service process.

Check the usuals like permissions, path existence, framework version, etc.




回答2:


This worked for me. Writing to MemoryStream and then Write the MemoryStream to the Output. Reasoning and code is here: https://weblog.west-wind.com/posts/2006/Oct/19/Common-Problems-with-rendering-Bitmaps-into-ASPNET-OutputStream




回答3:


I changed my Image over load method to

Image.Save(context.HttpContext.Response.OutputStream, ImageCodecInfo encoder, EncoderParameters encoderParams)

earlier i was using Image.Save(context.HttpContext.Response.OutputStream,ImageFormat)

after changing the overload method for save , it fixed the error.




回答4:


I installed my application on a Windows 7 machine by running as administrator.

This worked for me.




回答5:


I had something similar a while back ... usually to do with security. Don't copy the png over from dev, (if you have one) the server probably won't be able to overwrite and make sure the asp proccess has write access to the dir you're attempting to save to.




回答6:


It is probably that the asp.net worker process does not have permision to create a file where you are trying to save the image on the server.




回答7:


This happened for me when the file already existed. Deleting the file before save resolved the problem. What an incredibly unhelpful error message.



来源:https://stackoverflow.com/questions/3009163/a-generic-error-occurred-in-gdi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!