【发布时间】:2015-10-04 04:24:07
【问题描述】:
在 android lollipop 之前的任何版本上,以下代码都可以正常工作。 出于某种原因,从某个版本的android(大约5.0)开始,每当从相机捕获图像时,屏幕都会向右和向后旋转90度(不仅我的设备上的自动旋转关闭,我的活动被定义为肖像,它根本不应该旋转!)。一旦屏幕旋转回来,ImageView 就会呈现上一个(原始)图像。有什么建议吗?
相机意图:
if (result.equals("CAMERA"))
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, RESULT_IMAGE_CAPTURE);
}
实际操作:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Bitmap bmp = null;
if (requestCode == RESULT_IMAGE_CAPTURE && resultCode == RESULT_OK && data != null)
Bitmap bmp = (Bitmap) data.getExtras().get("data");
if (bmp != null)
{
mProfilePicPath = ImageHandler.saveBitmap(bmp , "", "image_name");
mProfilePic.setImageBitmap(bmp);
}
}
编辑:显然,当从相机意图返回我的活动时,不仅仅是要调用的 onResume() 方法,而是调用 onCreate() 方法,而且不仅仅是一次,而是两次! 第一次没有问题,因为它之后调用了onActivityResult方法。 但是,第二次重新启动 mProfilePic(我的 ImageView)和 mProfilePicPath,我想稍后使用它们。有什么想法吗?
【问题讨论】:
-
你得到什么错误?
-
@DDsix,我没有收到任何错误
-
@MarkySmarky 那里的答案基本上是我的代码,或多或少:)
标签: android camera imageview android-5.0-lollipop