c# - TypeConverter to convert byte[] to Bitmap -


i have this:

byte[] ar = new byte[arrayansammlung[durchlaeufer].length]; arrayansammlung[durchlaeufer].copyto(ar, 0); typeconverter tc = typedescriptor.getconverter(typeof(bitmap)); try {     bild = (bitmap)tc.convertfrom(ar); } catch (exception ddd) {     console.writeline(ddd.tostring()); } 

ar contains bitmap data, ie blue-green-red-alpha-blue....

i trying convert bitmap bild. console shows:

a first chance exception of type 'system.argumentexception' occurred in system.drawing.dll system.argumentexception: invalid parameter.    @ system.drawing.image.fromstream(stream stream, boolean useembeddedcolormanagement, boolean validateimagedata)    @ system.drawing.imageconverter.convertfrom(itypedescriptorcontext context, cultureinfo culture, object value)    @ system.componentmodel.typeconverter.convertfrom(object value)    @ sk.mainwindow.thread() in mainwindow.xaml.cs:zeile 523. 

how solve problem?

try :

public static bitmap bytestobitmap(byte[] bytearray) {     using (memorystream ms = new memorystream(bytearray))     {         bitmap img = (bitmap)image.fromstream(ms);         return img;     } } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -