在风景中一切正常但如果我垂直拿着手机,输出图片仍处于横向模式。有什么帮助吗?
我尝试按照建议使用此代码,但无论我如何拿着手机,我得到的唯一方向是ORIENTATION_NORMAL。
ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotateImage(bitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotateImage(bitmap, 180);
break;
// etc.
}
的onCreate:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View decorView = getWindow().getDecorView();
i = 0;
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Create an instance of Camera
mCamera = getCameraInstance();
//Setparams just sets the focus mode and picture size
setParams();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
//Capture click listener
Button captureButton = (Button) findViewById(R.id.button_capture);
captureButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
mCamera.takePicture(null,null,mPicture);
Log.d("TAG", "Picture 0 taken");
}
}
);
}
onPictureTaken: - 应用程序需要5张图片将它们一个接一个地保存为jpegs,然后在asyncTask中创建一个带有它们的gif。唯一的一点是,无论您如何握住手机,它都会以横向模式保存所有图片。
private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE, i);
if (pictureFile == null) {
Log.d(TAG, "Error creating media file, check storage permissions: "
);
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
i++;
//starts camera preview after taking picture
mCamera.startPreview();
if(i<5){
mCamera.takePicture(null,null,mPicture);
Log.d("TAG", "Picture taken" + i);
}
if(i==5){
new asyncGIF().execute();
i=0;
}
}
};