【发布时间】:2016-02-08 18:03:27
【问题描述】:
我使用这段代码从图库中获取图像,然后在保存之前裁剪图像。它运行良好,适用于内置画廊的 android,但在 onActivityResult 方法中给出 NullPointerException,我们在 android 上使用谷歌照片应用程序获得 extras.getParcelable("data")。任何帮助,将不胜感激。在此先感谢:D
//This is called in oncreate() on clicking the upload from gallery button.
Intent galleryIntent = new Intent(Intent.ACTION_PICK , android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
galleryIntent.putExtra("crop", "true");
startActivityForResult(galleryIntent,PICK_FROM_FILE);
//This is called on onActivityResult() method
if (requestCode == PICK_FROM_FILE && data != null) {
Bundle extras = data.getExtras();
//get the cropped bitmap from extras
Bitmap thePic = extras.getParcelable("data");
//do whatever with thePic
}
【问题讨论】:
-
参考this
-
@JohnJoe 感谢分享链接,但请您给我解决问题的方法,在此我必须先选择图像,然后在保存之前对其进行裁剪。
-
选中的图片可以显示在imageView上吗?
-
@JohnJoe ,如果我从 android 图库应用程序中选择它,则图像视图已设置,但如果我选择照片应用程序,则它在 extras.getParcelable("data") 上给出 NullPointerException。跨度>
标签: android crop google-photos