我的应用程序允许用户拍摄视频:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_VIDEO_REQUEST);
或图片:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
对于照片的情况,我可以判断它们是否是在非横向模式下拍摄的,然后在上传到网站之前将它们旋转:
ExifInterface exif = new ExifInterface(fileName);
int exifOrientation = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION));
float rotate = 0;
switch (exifOrientation){
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
}
if(rotate > 0){
Bitmap bitmap = BitmapFactory.decodeFile(fileName);
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
OutputStream outStream = context.getContentResolver().openOutputStream(Uri.fromFile(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
}
我如何用视频实现相同的效果?