gpt4 book ai didi

Android - 如何从 ClipData 获取图像?

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

我正在创建一个能够一次上传多于 1 张图片的图片 uploader 。

galerijButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
});

...

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
if(imageReturnedIntent.getData() != null){
//If uploaded with Android Gallery (max 1 image)
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
photos.add(yourSelectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
//If uploaded with the new Android Photos gallery
ClipData clipData = imageReturnedIntent.getClipData();
for(int i = 0; i < clipData.getItemCount(); i++){
clipData.getItemAt(i);
//What now?
}
}
}
break;
....

我想将所有选定的图像添加到我的照片数组中,这是一个 ArrayList<Bitmap> .我必须以某种方式转换 ClipData.ItemBitmap ,但是如何呢?

最佳答案

试试这个

ClipData.Item item = clip.getItemAt(i);
Uri uri = item.getUri();

现在您有了图像的 URI

我猜你现在知道该怎么做了。干杯:)

关于Android - 如何从 ClipData 获取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21751429/

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