I have looked around but nothing seemed to really match my problem.
I am trying to save a picture from a direct link. Either as a gif or png depending on what is needed. Every time I try to save the file I get said error.
public void SaveImage(String ID, string pokemonName, bool isShiny, ImageFormat imageFormat, bool isSprite = false)
{
Directory.CreateDirectory(@"C:\Users\Cardon\Documents\Pokemon\" + ID + " - " + pokemonName);
var tmpImageFormat = (imageFormat == ImageFormat.Gif) ? "gif" : "png";
var url = (isSprite)
? "http://www.serebii.net/pokedex-bw/icon/" + ID + "." + tmpImageFormat
: (isShiny) ? "http://www.serebii.net/Shiny/BW/" + ID + "." + tmpImageFormat
: "http://www.serebii.net/blackwhite/pokemon/" + ID + "." + tmpImageFormat;
var pictureBox = new PictureBox();
pictureBox.Load(url);
if (pictureBox.ImageLocation == null) return;
pictureBox.Image.Save(@"C:\Users\Cardon\Documents\Pokemon\" + ID + " - " + pokemonName, imageFormat);
}
System.Runtime.InteropServices.ExternalException was unhandled
Message=A generic error occurred in GDI+.
Source=System.Drawing
ErrorCode=-2147467259
StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at PokemonDataExtractor.frmMain.SaveImage(String ID, String pokemonName, Boolean isShiny, ImageFormat imageFormat, Boolean isSprite) in C:\Users\Cardon\Desktop\PokemonDataExtractor\PokemonDataExtractor\frmMain.cs:line 297
at PokemonDataExtractor.frmMain.btnExtract_Click(Object sender, EventArgs e) in C:\Users\Cardon\Desktop\PokemonDataExtractor\PokemonDataExtractor\frmMain.cs:line 79
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at PokemonDataExtractor.Program.Main() in C:\Users\Cardon\Desktop\PokemonDataExtractor\PokemonDataExtractor\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
The error only occurres when I try to save the image, some say it is because of write access but I am positive that my account has write has write access to those files. Even though I am positive I still may be wrong due to wrong thinking.
Any solution would be greatly appreciated.
Thanks in Advance.