Trouble working with the camera in onActivityResult

故事扮演 提交于 2019-11-27 08:43:39

Your Activity is probably being destroyed and re-created when the camera activity is going off. Maybe try saving photoPath into the Bundle in onSaveInstanceState and then fish it back out in onCreate (make sure to check for nulls in onCreate when you do so)?

Song Vo

I can not using the data. But I think you need changed as follow

photo to become general variable.

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

So, you must be take it from this folder:

Bitmap photo = Media.getBitmap(getContentResolver(), Uri.fromFile(photo) );

I follow your code and change.

Basically put, using

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

works well

Before placing in an imageView, make sure that you compress the image since it is extremely large when saving this way.

int newWidth = bm.getWidth();
int newHeight = bm.getHeight();
while(newWidth > 300){
    newWidth = newWidth/2;
newHeight = newHeight/2;
}
mImagePlaceHolder.setImageBitmap(Bitmap.createScaledBitmap(bm, newWidth, newHeight, false));
Jaden Gu

I struggled with this problem and found another solution: just use code like this:

Bitmap bitmap = data.getExtras().getParcelable("data");

and you can get the bitmap.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!