Android的棒棒糖问题 - 无法从相机载入图像的ImageView [英] Android Lollipop issue - Cannot load image from camera to ImageView
问题描述
在Android的棒棒糖之前的任何版本,下面的code正常工作。 出于某种原因,从某个版本的Android(5.0左右),当图像从相机拍摄的,画面旋转90度到右侧和背面(不只是我的设备上自动旋转是关闭的,我的行为被定义为肖像,它不应该被旋转了!)。当屏幕旋转回来,ImageView的presents的previous(原件)的图像。有什么建议?
On any version before android lollipop, the below code works fine. For some reason, from a certain version of android (around 5.0), whenever an image is captured from camera, the screen rotates 90 degrees to the right and back (Not only auto-rotate on my device is off, my activity is defined as portrait, it's not supposed to be rotating at all!). Once the screen rotates back, the ImageView presents the previous (original) image. Any suggestions?
相机意图:
if (result.equals("CAMERA"))
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, RESULT_IMAGE_CAPTURE);
}
实际的行动:
The actual action:
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,我想以后使用。任何想法?
EDIT: Apparently when going back to my activity from the camera intent, rather than just the onResume() method to be called, the onCreate() method is called, and not just once, but twice! The first time is not a problem, since the onActivityResult method called after it. The second time, though, re-initiates both mProfilePic (my ImageView) and mProfilePicPath, which I want to use later. Any ideas?
推荐答案
确定,显然这是问题(和解决方案) - <一href="http://stackoverflow.com/questions/10411009/activity-killed-oncreate-called-after-taking-picture-via-intent">Activity通过意向拍照
OK, apparently this was the problem (and the solution) - Activity killed / onCreate called after taking picture via intent
我没有在我的清单该行(虽然我没有定义我的活动人像): 机器人:configChanges =定位| keyboardHidden |屏幕尺寸
I didn't have that line in my manifest (though i did define my activity as portrait): android:configChanges="orientation|keyboardHidden|screenSize"
这篇关于Android的棒棒糖问题 - 无法从相机载入图像的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!