架构说主页 > 架构说 >
Android 关于获取摄像头帧数据解码
新闻来源:凯发K 添加时间:2019-01-26

// 创建保存照片文件夹
	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;
			}

		}
	};

实现摄像头拍照需求。

http://www.bkjia.com/Androidjc/770812.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/770812.htmlTechArticle// 创建保存照片文件夹private void CreateFileJPG() {File file = new File("/sdcard/image");if (!file.exists()) {try {file.mkdirs();} catch (Exception e) {// TODO: handle exc...

本文源自: 凯发K8

架构说
联系方式