Displaying a jpeg image sent over the network in a picturebox



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.

.



Relevant Pages

  • RE: Displaying a jpeg image sent over the network in a picturebox
    ... try Image.FromStream(MemoryStream); ... I start off with a bitmap image. ... I encode it as a jpeg and send it ...
    (microsoft.public.dotnet.framework.drawing)
  • www.CeBeans.com - new program listings - Nov 16 2009
    ... shot as a bitmap image. ... This program allows you to take screen shot of the PocketPC display and FTP ... This program allows you to convert JPEG images into bitmap zoomed image. ... This program allows you to take customized JPEG screen shots of your ...
    (microsoft.public.pocketpc)
  • Re: WMM 2.1 Hangs and crashs
    ... I'm sorry to say that MPeg is not supported. ... > JPeg images are in a sense like MPeg. ... > these variations it would seem that Movie Maker cannot. ... > The solution is the same for both, convert it to a bitmap On the ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: large images / EPSI
    ... output format). ... Doesn't converting to a bitmap ... such as JPEG or PNG? ... I'm pretty sure, by the way, that higher resolution would be needed; ...
    (comp.text.tex)
  • Re: Embed an image in an email?
    ... server but rather ship the jpeg in the email itself)? ... Basically you encode the picture (probably Base-64) and then include it in ...
    (microsoft.public.dotnet.framework.drawing)

Quantcast