c# - Programmatically detect and convert “pixel format not supported” images -


when debug wpf apps first-chance exception on, got lot of notsupportedexception message “pixel format not supported”. if ignore exception, images work fine want fix them anyway chance @ other first-chance exceptions.

currently looking callstack figure out file name, convert manually using image editor, , restart debugging catch next one. however, wonder if can automate small console app detect such images , convert them format wpf happy with.

i've read references limited image knowledge unable understand exact problem wpf having these images, or how can program detect these images if they're loaded xaml, or how convert them programmatically format wpf happy with.

there various file formats - png being 1 - several different image formats stored in same file. in case it's image depth (bits per pixel). .net doing trying open file common format first , when fails it's trying different formats until gets 1 works.

as rare event it's sensible try open file , trap resultant exception , try again.

there's nothing can exception raised , (more importantly) handled within image creation code.

you have encountered 1 of big dangers of turning "first chance exception" on. number of these "false" errors. mode should used real problems encountering when have no idea exception being raised. image read haven't got error case.


if .net can't read file format need need trap exception , "something sensible" in handler:

foreach (string file in files) {     try     {         // code process image         var image = image.fromfile(file);     }     catch (notsupportedexception ex)     {         var process = new process();         process.exited += exitedhandler;         // call other app convert file         string arguments = file + command line arguments necessary         process.start(conversion program, arguments);     } 

exitedhandler can call code processes image there's no need loop on converted files again.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -