目前我在開發的是15的版本是可以用的
Parameters parameters = camera.getParameters();
parameters.setRotation(90);
parameters.set("rotation", 90);
那如果希望在拍照完成時處理則可以寫在PictureCallback的onPictureTaken方法內,利用Matrix來做翻轉
只是在onPictureTaken有可能會造成OutOfMemoryError
private PictureCallback pictureCallBack = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
// 進行解碼
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
// 矩陣
Matrix matrix = new Matrix();
float angle = 90;
// 翻轉角度
matrix.postRotate(angle);
Bitmap rotaBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
bitmap = null;
// 設定檔案存放位置
File file = new File(new Date().getTime() + ".jpg");
FileOutputStream fileOutputStream = new FileOutputStream(file);
rotaBitmap.compress(CompressFormat.JPEG, 85, fileOutputStream);
// 寫入檔案
fileOutputStream.flush();
fileOutputStream.close();
// 重新開啟預覽
camera.startPreview();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};