Displaying a jpeg image sent over the network in a picturebox
- From: bull.enteract@xxxxxxx
- Date: 4 Jun 2005 14:23:27 -0700
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();
ImageCodecInfo myCodecInfo;
EncoderParameter myParameter;
EncoderParameters myParameters;
myCodecInfo = Form1.GetEncoderInfo("image/jpeg");
myParameters = new EncoderParameters(1);
Int32 quality = 50;
myParameter = new
EncoderParameter(System.Drawing.Imaging.Encoder.Quality,
(long)quality);
myParameters.Param[0] = myParameter;
workerBmp.Save(memStream, myCodecInfo, myParameters);
......memStream.Position = 0;
byte[] byteData = memStream.ToArray();
networkStream.Write(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.Read(dataBuffer, totalBytesRead,
dataBuffer.Length - totalBytesRead)) < (dataBuffer.Length -
totalBytesRead))
totalBytesRead += bytesRead;
Now what? I see tons of info out there showing you how to Encode a
bitmap as a jpeg file.. but not the other way around. I can create a
jpeg Decoder Info object..i.e.
ImageCodecInfo myCodecInfo;
myCodecInfo = Form1.GetDecoderInfo("image/jpeg");
But what do I do with it? I also tried dropping the buffer into a
MemoryStream and just instantiating a Bitmap from the stream...i.e..
MemoryStream memStream = new MemoryStream(dataBuffer);
Bitmap bmp = new Bitmap(memStream);
But that just gets me the following Exception..
An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll
Additional information: Invalid parameter used.
.
- Prev by Date: Re: PCX files in dot net
- Next by Date: Getting a jpeg out of a byte[]..(couldn't edit my last post..this one is clearer)
- Previous by thread: Graphics.FromImage(bmp).GetHdc as source for BitBlt?
- Next by thread: Getting a jpeg out of a byte[]..(couldn't edit my last post..this one is clearer)
- Index(es):
Relevant Pages
|