Okay, the situation is this: I saved a Bitmap using the Bitmap.Save method into a MemoryStream and then I used the MemoryStream.ToArray() method to turn it into a Byte[] array. I used a Socket to send the the Byte[] (buffer) and recieved the buffer in a remote side (Mostly on a Pocket PC), I cannot seem to find a way to return that Byte[] back to a Bitmap, I tried using the MemoryStream(Byte[]) constructor in order to save it on a memory stream, and then using the Bitmap(System.IO.Stream) constructor but it returns an exception stating that it is an invalid parameter or argument, I would thank all who could help me solve this problem, here's an example of what I have been doing to send and recieve my Bitmap: //Sending: Bitmap bmp = new Bitmap(@openDialog1.FileName); System.IO.MemoryStream memImage = new MemoryStream(); bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Jpeg); byte[] data = memImage.ToArray(); IPEndPoint endPoint = new IPEndPoint(this.theIP,651); //this.theIP = my IP socket.Connect(endPoint); socket.Send(data,0,data.Length,SocketFlags.None); //Recieving IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("..my Ip.."),651); this.socket.Bind(endPoint); this.socket.Listen(10); Socket connected = socket.Accept(); byte[] byteResponse = new byte[1024]; connected.Receive(byteResponse,SocketFlags.None); MemoryStream memory = new MemoryStream(byteResponse); Bitmap bmp = new Bitmap(memory); //generates invalid argument exception this.pictureBox1.Image = bmp; Could anyone help me and also point out my errors here, I would be a great help, thanks in advanced.:) P.S. I really would prefer a method that would work in the Compact Framework, since I am working with a Pocket PC as a reciever.:)
G
Gakujin
@Gakujin
Posts
-
How to change from Byte[] to Bitmap on a Pocket PC -
How can I send an Image over a socket connection?I wish to know, if there is any way to send an image from one form to another using a socket conection. Say like one form can send an image to another form on a remote computer that recieves it and views it. Can it be done just using sockets? Thanks in advanced :)