我从客户端套接字接收jpeg图像(图像大小:50KB)并保存在模拟器SD卡中.从那里我在Imageview中显示jpg图像.但是我想在将图像保存到SD卡之前显示图像,因为我们的android appli将从套接字接收连续图像,如果我按照接收,保存和显示方法那么它将变得非常慢的过程,所以提高我想要的速度仅从ram显示.为此,我需要将图像阵列临时保存在RAM上.从那里我计划通过使用单独的线程显示和保存.那么请指导我如何从字节数组中显示图像.
注意:我从socket接收JPEG图像,而不是.bmp或.gif或.png.
下面是我从tcp socket接收图像的代码.(它的工作正常)(注意:这是在单独的线程中完成的,不要在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,0,mybytearray.length);
current = bytesRead;
do {
bytesRead …Run Code Online (Sandbox Code Playgroud)