byte[] result; using (MemoryStream memoryStrem = new MemoryStream()) { JpegBitmapEncoder encoder = new JpegBitmapEncoder(); System.Drawing.Bitmap image = new System.Drawing.Bitmap("skin.jpg"); image.Save(memoryStrem, ImageFormat.Bmp); result = memoryStrem.ToArray(); } TcpListener tcpListener; TcpClient tcpClient; NetworkStream networkStream; tcpListener = new TcpListener(IPAddress.Any, 5554); IPEndPoint clientPoint; while (true) { try { tcpListener.Start(); } catch (Exception exp) { MessageBox.Show(exp.Message); return; } try { tcpClient = tcpListener.AcceptTcpClient(); } catch (Exception exp) { MessageBox.Show(exp.Message); return; } clientPoint = (IPEndPoint)(tcpClient.Client.RemoteEndPoint); networkStream = tcpClient.GetStream(); networkStream.Write(result, 0, result.Length); networkStream.Flush(); networkStream.Close(); tcpClient.Close(); }
c#端的程序如上面所示,具体的思路就是将一副图片按照一定的格式编码后得到byts的数组,
问题是在android端如何解码,转换成androi下的bitmap实例呢?希望那位大侠提供实例代码!!
问题结局了,在客户端得到byte[]之后用一下语句解码
Bitmap bitmap = BitmapFactory.decodeByteArray(buffer, 0, count);
开始一直出错原来是buffer设置的太小了.感谢各位的帮忙.
客户端拿到byte[]后,再找个jpeg的库加载就行了。