IP摄像机:设置ImageView的与IP摄像机的字节数组数据来并下载位图SD卡作为影像

问题描述 投票:0回答:1

我们有一个自定义的IP摄像头和一个同伴的Android服务,提供摄像头输入的字节[](通过socket通信)。

void onCameraData(byte[] picData)

我需要在方法调用之后做到以下几点,

  1. 显示在活动在ImageView的接收到的字节数组数据。
  2. 下载显示的图像/位图到SD卡。

由于相机饲料有20 FPS,我想最大的1000个图像存储到SD卡。这是检查从网络摄像机的图像数据被正确接收在应用程序侧。

ip-camera
1个回答
0
投票
  1. 与字节数组设定的图像图。 void setImageViewWithByteData(byte[] picData) { runOnUiThread(new Runnable() { @Override public void run() { try { byte[] data = Arrays.copyOf(picData, picData.length); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); if (ivImageView != null){ ivImageView.invalidate(); ivImageView.setImageBitmap(bitmap); downloadFiles(bitmap); } } catch (Exception e) { e.printStackTrace(); } } }); }
  2. 下载1000张SD卡 synchronized void downloadFiles(Bitmap bmp){ new Thread(new Runnable() { @Override public void run() { try{ if(counter <=1000) {//slip the files after 1000 frames Bitmap bitmap = bmp; String path = Environment.getExternalStorageDirectory().toString(); OutputStream fOut = null; File file = new File(path, "ipcamera_" + (++counter) + ".jpg"); // the File to save , append increasing numeric counter to prevent files from getting overwritten. fOut = new FileOutputStream(file); Bitmap pictureBitmap = bitmap; // obtaining the Bitmap bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut); // saving the Bitmap to a file compressed as a JPEG fOut.flush(); fOut.close(); // do not forget to close the stream MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName()); bitmap.recycle(); bitmap = null; } } catch (Exception e) { e.printStackTrace(); } } }).start(); }
© www.soinside.com 2019 - 2024. All rights reserved.