【问题标题】:Import Pictures from Picasa in Motorola Xoom在 Motorola Xoom 中从 Picasa 导入图片
【发布时间】:2012-01-20 12:22:39
【问题描述】:

我编写了一个简单的代码,用于从任何支持图像的应用程序中导入图像

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);

从图库中导入图像时,代码可以正常工作,但只要我从我的摩托罗拉 xoom 中的 picasa 导入图像。它返回 null 并以 NullPointerException 强制关闭。

有人对此有任何想法吗?

【问题讨论】:

  • 你在哪里得到NllPointerException
  • 将activityresult上的图片作为位图导入并使用其属性后,我得到NullPointerException.....
  • Uri selectedImageUri = data.getData(); String selectedImagePath = imageUtil.getPath(selectedImageUri,Main.this); BitmapDrawable d =(BitmapDrawable)BitmapDrawable.createFromPath(selectedImagePath);现在在访问“d.getWidth”时,我得到 NullPointerException..

标签: android


【解决方案1】:

ACTIVITYRESULT_CHOOSEPICTURE 是调用 startActivity(intent, requestCode); 时使用的 int;

public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    final InputStream is = context.getContentResolver().openInputStream(intent.getData());
    final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
    is.close();
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多