Reputation: 13723
I've been having problems with I code I wrote. What this code does is download a picture from my server and puts it inside a PDF document. I've narrowed it down to a problem with the image being downloaded.
At first, I thought it was a problem with my project so I've created a new Console Application with just that code to test it out - but that happens on it as well.
What I'm trying to do is simple - download a picture with WebClient and save it to the disk:
WebClient oWebClient = new WebClient();
byte[] oImageBytes = oWebClient.DownloadData("http://images1.ynet.co.il/PicServer3/2013/12/25/5058381/505838001000100396220.jpg");
ImageConverter oConverter = new ImageConverter();
Image oImg = (Image)oConverter.ConvertFrom(oImageBytes);
oImg.Save("d:\\temp\\1.jpg");
The image url in the example is taken from a local news site and fails as well.
The very strange thing is that on windows 7 and earlier it works. It fails on Windows8 and Windows Server 2012 with the following error:
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
Additional information: A generic error occurred in GDI+.
This is the StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at System.Drawing.Image.Save(String filename)
at ConsoleApplication1.Program.Main(String[] args) in c:\Users\Ophir\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 23
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I've tried searching the web, but all solutions I found didn't work in my case.
The directory that I'm trying to save to has sufficient permissions.
Anyone has any idea to why this is happening ?
Thanks
Upvotes: 0
Views: 718
Reputation: 7445
What about to save data as is?
byte[] oImageBytes = oWebClient.DownloadData("http://images1.ynet.co.il/PicServer3/2013/12/25/5058381/505838001000100396220.jpg");
File.WriteAllBytes("d:\\temp\\1.jpg", oImageBytes);
Upvotes: 1