Ok, I start off with a bitmap image. I encode it as a jpeg and send it
across the network and pick it up on the other end. Now I have the
jpeg image on the other end as an arrray of bytes and I want to display
it in a picturebox control. How the heck do I convert this byte[] into
a bitmap?
Here is the pertinent code I use to convert it to a jpeg on the server
and send it to client..
....Bitmap workerBmp = new Bitmap(bmp);
MemoryStream memStream = new MemoryStream();
workerBmp.Save( memStream, ImageFormat.Jpe g);
byte[] byteData = memStream.ToArr ay();
networkStream.W rite(byteData, 0, byteData.Length );
So now I pick up the jpeg data on the client and that's where I am
stuck.. how do I get this data into a form that a picturebox can
understand?
I read the data...
while ((bytesRead = networkStream.R ead(dataBuffer, totalBytesRead,
dataBuffer.Leng th - totalBytesRead) ) < (dataBuffer.Len gth -
totalBytesRead) )
totalBytesRead += bytesRead;
Now what? I tried dropping the buffer into a MemoryStream and just
instantiating a Bitmap from the stream...i.e..
MemoryStream memStream = new MemoryStream(da taBuffer);
Bitmap bmp = new Bitmap(memStrea m);
//Image img = Image.FromStrea m(memStream); Same result if I use this
I get the following Exception..
An unhandled exception of type 'System.Argumen tException' occurred in
system.drawing. dll
Additional information: Invalid parameter used.
A point in the right direction please..
across the network and pick it up on the other end. Now I have the
jpeg image on the other end as an arrray of bytes and I want to display
it in a picturebox control. How the heck do I convert this byte[] into
a bitmap?
Here is the pertinent code I use to convert it to a jpeg on the server
and send it to client..
....Bitmap workerBmp = new Bitmap(bmp);
MemoryStream memStream = new MemoryStream();
workerBmp.Save( memStream, ImageFormat.Jpe g);
byte[] byteData = memStream.ToArr ay();
networkStream.W rite(byteData, 0, byteData.Length );
So now I pick up the jpeg data on the client and that's where I am
stuck.. how do I get this data into a form that a picturebox can
understand?
I read the data...
while ((bytesRead = networkStream.R ead(dataBuffer, totalBytesRead,
dataBuffer.Leng th - totalBytesRead) ) < (dataBuffer.Len gth -
totalBytesRead) )
totalBytesRead += bytesRead;
Now what? I tried dropping the buffer into a MemoryStream and just
instantiating a Bitmap from the stream...i.e..
MemoryStream memStream = new MemoryStream(da taBuffer);
Bitmap bmp = new Bitmap(memStrea m);
//Image img = Image.FromStrea m(memStream); Same result if I use this
I get the following Exception..
An unhandled exception of type 'System.Argumen tException' occurred in
system.drawing. dll
Additional information: Invalid parameter used.
A point in the right direction please..
Comment