简体   繁体   中英

In GDI + generic error occurred

I save Image but have error In GDI + generic error occurred. How to get rid of the error?

 public void save_all_image(string path_directory)
    {
        for (int i = 0; i < list_real_foto.Count; i++)
        {
            string format = list_format_file[i].ToLower();
            list_real_foto[i].Save(path_directory + "\\" + i.ToString() + "." + format);//In GDI + generic error occurred
        }
    }

GDI+ is about as bad as it gets when it comes to error messages. What I would do in your case is to check that you are saving it to a correct path and then make sure that you have permission to save files there.

You should also avoid concatenating strings to build paths, there is a great helper-class available for that in System.IO.Path called Combine() . You might also want to consider using string.Format() to make the code a bit easer to read.

list_real_foto[i].Save(System.IO.Path.Combine(path_directory, string.Format("{0}.{1}", i, format));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM