Android examples for android.graphics:YuvImage
from Preview Data to YuvImage
//package com.java2s; import android.graphics.ImageFormat; import android.graphics.Rect; import android.graphics.YuvImage; import android.hardware.Camera; import android.util.Log; import java.io.ByteArrayOutputStream; public class Main { public static final String TAG = "CameraUtils"; static byte[] fromPreviewData(byte[] bytes, Camera.Size previewSize) { int width = previewSize.width; int height = previewSize.height; log("Converting preview data from size " + width + ", " + height); // Convert bytes first to YUV image, then to RGB YuvImage yuvImage = new YuvImage(bytes, ImageFormat.NV21, width, height, null);//from w w w .j a va2s.c om ByteArrayOutputStream jpegOutput = new ByteArrayOutputStream(); yuvImage.compressToJpeg(new Rect(0, 0, width, height), 90, jpegOutput); return jpegOutput.toByteArray(); } public static void log(String msg) { Log.v(TAG, msg); } }