我準備的視圖(使用setDisplayOrientation())處於肖像模式,但生成的圖像(使用takePicture()拍攝,使用SaveImageTask保存)處於橫向模式。如何旋轉使用takePicture拍攝的圖像?
這是我的預覽&捕捉代碼:
public void startPreview() {
this.mCamera.setDisplayOrientation(90);
try {
this.mCamera.setPreviewDisplay(this.mSurfaceHolder);
this.mCamera.startPreview();
} catch (Exception e) {
Log.d("camera" , "in startPreview Catch");
}
}
public void captureNow(View view) {
this.mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
this.startPreview();
}
這是我拍攝的圖像保存代碼:
public class SaveImageTask extends AsyncTask<byte[], Void, Void> {
@Override
protected Void doInBackground(byte[]... data) {
FileOutputStream outStream = null;
// Write to SD Card
try {
File dir = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "camTest");
dir.mkdirs();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
outStream = new FileOutputStream(outFile);
outStream.write(data[0]);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
return null;
}
}
我如何可以旋轉拍攝的圖像?似乎傳感器始終處於橫向模式。(注:API 21)