byte[] jpegFromPreview(byte[] currentPreview) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Parameters parameters = mCamera.getParameters();
Size size = parameters.getPreviewSize();
YuvImage image = new YuvImage(currentPreview, parameters.getPreviewFormat(), size.width, size.height, null);
image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), quality, baos);
byte[] jpeg = baos.toByteArray();
float rotation = (float) 0.;
if (cameraId == 1 && mDisplay.getRotation() == Surface.ROTATION_0)
rotation = (float) 270.;
else if (cameraId == 0 && mDisplay.getRotation() == Surface.ROTATION_0)
rotation = (float) 90.;
if (debug) Log.i(TAG, "cameraId: " + cameraId + ", getRotation: " + mDisplay.getRotation() + ", rotation: " + rotation);
if (rotation != 0.) {
// This is the same image as the preview but in JPEG and not rotated
Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
ByteArrayOutputStream rotatedStream = new ByteArrayOutputStream();
// Rotate the Bitmap
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
// We rotate the same Bitmap
bitmap = Bitmap.createBitmap(bitmap, 0, 0, image.getWidth(), image.getHeight(), matrix, false);
// We dump the rotated Bitmap to the stream
bitmap.compress(CompressFormat.JPEG, 50, rotatedStream);
jpeg = rotatedStream.toByteArray();
// whew
}
return jpeg;
}
CTandroidAV.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:cloudturbine
作者:
评论列表
文章目录