大佬教程收集整理的这篇文章主要介绍了android – 如何直接从字节数组中显示JPEG图像(保存图像之前)?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
注意:我从socket接收JPEG图像,而不是.bR_418_11845@p或.gif或.png.
下面是我从tcp socket接收图像的@L_675_10@. (工作正常)
(注意:这是在单独的线程中完成的,不要在UI线程中尝试.)
public byte[] mybytearray = new byte[310000]; privatE int bytesRead=0; privatE int current = 0; ServerSocket serverSocket = new ServerSocket(SERVERPORT); Socket client = serverSocket.accept(); try { myDir=new File("/mnt/sdcard/saved_images"); if (!myDir.exists()){ myDir.mkdir(); }else{ Log.d("ServerActivity","Folder Already created" ); } String fpath = "/image0001.jpg"; File file = new File (myDir,fpath); if (file.exists ()) file.delete (); InputStream is = client.geTinputStream(); FiLeoutputStream fos = new FiLeoutputStream(filE); bufferedoutputstream bos = new bufferedoutputstream(fos); bytesRead = is.read(mybytearray,mybytearray.length); current = bytesRead; do { bytesRead = is.read(mybytearray,current,(mybytearray.length-current)); if(bytesRead >= 0) current += bytesRead; } while(bytesRead > -1); bos.write(mybytearray,current); Log.d("ServerActivity","ReconstrucTing Image from array"); bos.flush(); bos.close(); fos.flush(); fos.close(); is.close(); client.close(); serverSocket.close(); } catch (Exception E) { e.printStackTrace(); }
do { bytesRead = is.read(mybytearray,(mybytearray.length-current)); if(bytesRead >= 0) current += bytesRead; } while(bytesRead > -1); ByteArrayInputStream inputStream = new ByteArrayInputStream(myByteArray); bitmap = BitmapFactory.decodeStream(inputStream); ImageView picture = new ImageView(this); picture.setImageBitmap(bitmap); bos.write(mybytearray,current);
以上是大佬教程为你收集整理的android – 如何直接从字节数组中显示JPEG图像(保存图像之前)?全部内容,希望文章能够帮你解决android – 如何直接从字节数组中显示JPEG图像(保存图像之前)?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。