@Override
// Decode the image data and rotate it to the proper orientation.
// then run the callback, if any, on the image to do post processing
protected Boolean doInBackground(Object... params) {
byte[] data = (byte[]) params[0];
Camera camera = (Camera) params[1];
Camera.Parameters parameters = camera.getParameters();
int format = parameters.getPreviewFormat();
//YUV formats require more conversion
if (format == ImageFormat.NV21 || format == ImageFormat.YUY2 || format == ImageFormat.NV16) {
int w = parameters.getPreviewSize().width;
int h = parameters.getPreviewSize().height;
// Get the YuV image
YuvImage yuv_image = new YuvImage(data, format, w, h, null);
// Convert YuV to Jpeg
Rect rect = new Rect(0, 0, w, h);
ByteArrayOutputStream output_stream = new ByteArrayOutputStream();
yuv_image.compressToJpeg(rect, 100, output_stream);
byte[] imageBytes = output_stream.toByteArray();
Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
Matrix transform = new Matrix();
if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
transform.preScale(-1, 1);
}
transform.postRotate(mCameraRotation);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), transform, true);
if (mCapturedCapturedImageCallbackAsync != null) {
mCapturedCapturedImageCallbackAsync.execute(bitmap);
}
}
return null;
}
CameraPreview.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:ProjectOxford-Apps-MimickerAlarm
作者:
评论列表
文章目录