C# convert Bytearray to System.Draw.Image

Hello,

I need to convert a Byte array back into an image. If I do that in the Unity IDE it is working but if I do it after I compiled it in windows it is not working anymore.
I am converting the Byte array into a Stream and try to convert the Stream into an image afterwards.

Stream tempstream;
System.Drawing.Image tempimage = null;
try{
			Byte[] ba;
			ba = (Byte[]) reader["FlagPng"];
			Debug.Log ("ByteArray: "+ba.ToString ());
			tempstream = new MemoryStream(ba);
			Debug.Log ("tempstream: "+tempstream.ToString ());
			tempimage = Image.FromStream(tempstream);
		}
		catch(Exception ex){
				Debug.LogError ("Errormessage 100: 

"+ex.Message );
Debug.LogError ("Errorsource 100:
"+ex.Source );
Debug.LogError ("Errorstacktrace 100:
"+ex.StackTrace);
Debug.LogError ("Errortargetsite 100:
"+ex.TargetSite);

		}

In my output_log is written:
ByteArray: System.Byte

tempstream: System.IO.MemoryStream

Errormessage 100:
Could not load type ‘System.IO.InternalBufferOverflowException’ from assembly ‘System.Drawing’.

Errorsource 100:
System.Drawing

Errorstacktrace 100:
at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] in :0

at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in :0

at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in :0

at SQLDatabase.ReadTblLanguages () [0x00000] in :0

Errortargetsite 100:
IntPtr InitFromStream(System.IO.Stream)

I can tell that the problem should be the line:
tempimage = Image.FromStream(tempstream);

All dlls I am using are mono dlls from the library directory of Unity.

Can anyone tell me how I can convert a stream into an image in Unity?

Thank you in advance.

I’m going to refer you to other questions - the problem is with System.Drawing:

http://forum.unity3d.com/threads/13191-System.Drawing-Question

demonstrated how to convert byte array to image and save in c# and upload image on server in aspnet using c# with an example. Find the c# source code below to convert byte array to image c# here