gpt4 book ai didi

android - 在我的应用程序中即时上传和 Google+ 图片

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:41 25 4
gpt4 key购买 nike

我目前遇到了以下问题:当我想从图库中检索图像时,我使用以下代码启动图库的 Intent 。

public void useGallery() {
this.intentbasedleave=true;
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, getString(R.string.pleaseselect_image)), IMAGE_PICK);
}

当我从图库中获取数据时,我使用此方法:

private void imageFromGallery(int resultCode, Intent data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();

this.updateImageView(BitmapFactory.decodeFile(filePath));
}

这有效,除非所选图片来自 Google+ 或即时上传。那么 BitmapFactory.decodeFile(filePath)) 似乎是空的?因为该方法引发空指针异常。

因此,我的问题是:如何使用来自 Google+ 和图库中即时上传的图片?

最佳答案

使用 BitmapFactory.decodeUri 而不是 BitmapFactory.decodeFile

您可以将您的方法 imageFromGallery 简化为

private void imageFromGallery(int resultCode, Intent data) {
Uri selectedImage = data.getData();
updateImageView(BitmapFactory.decodeUri(getContext().getContentResolver(), selectedImage));
}

(假设您可以从某处访问上下文)。

关于android - 在我的应用程序中即时上传和 Google+ 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13625049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com