Android 关于获取摄像头帧数据解码
时间:2014-05-15 06:39:58
收藏:0
阅读:434
// 创建保存照片文件夹 private void CreateFileJPG() { File file = new File("/sdcard/image"); if (!file.exists()) { try { file.mkdirs(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }
/** * 拍照保存图片 * */ public void saveMyBitmap() { FileOutputStream outStream = null; try { YuvImage yuvimage = new YuvImage(dataJPG, ImageFormat.NV21, cameraJPG.getParameters().getPreviewSize().width, cameraJPG .getParameters().getPreviewSize().height, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); yuvimage.compressToJpeg(new Rect(0, 0, cameraJPG.getParameters() .getPreviewSize().width, cameraJPG.getParameters() .getPreviewSize().height), 80, baos); outStream = new FileOutputStream(String.format( "/sdcard/image/%d.jpg", System.currentTimeMillis())); outStream.write(baos.toByteArray()); outStream.close(); Toast.makeText(getApplicationContext(), "照片保存成功!", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { } }
private PreviewCallback mPreviewCallback = new PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { synchronized (MainService.this) { dataJPG = data; cameraJPG = camera; } } };
实现摄像头拍照需求。
评论(0)