我从gallery.single图像获得单个和多个图像工作正常。然后通过剪辑数据获取多个图像到存储的数组list.how在ParcelFileDescriptor中添加多个图像?以及如何通过位图获取多个图像? 。获取多个图像或路径如何在服务器中发送多个或单个图像?
super.onActivityResult(requestCode, resultCode, data);
Uri selectedImageUri = null;
**ArrayList<Uri> mArrayUri = new ArrayList<>();**
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
if (data.getData() != null) {
selectedImageUri = data.getData();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (data.getClipData() != null) {
ClipData mClipData = data.getClipData();
for (int i = 0; i < mClipData.getItemCount(); i++) {
ClipData.Item item = mClipData.getItemAt(i);
System.out.println("item------->" + item);
Uri selectedImage = item.getUri();
System.out.println("selected------->" + selectedImage);
**mArrayUri.add(selectedImage);**
}
}
}
}
if (Build.VERSION.SDK_INT < 19) {
selectedImagePath = getPath(selectedImageUri);
Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath);
view.setImageBitmap(bitmap);
} else {
ParcelFileDescriptor parcelFileDescriptor;
try {
System.out.println("Image size------>" + mArrayUri.size());
**parcelFileDescriptor = getContentResolver().openFileDescriptor(selectedImageUri, "r");**
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
view.setImageBitmap(image);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public String getPath(Uri uri) {
if (uri == null) {
return null;
}
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
return uri.getPath();
}