I am using this library but they did not explain all details like other libraries on the github.
in onCreate
ImagePicker.create(this)
.folderMode(true) // folder mode (false by default)
.folderTitle("Folder") // folder selection title
.imageTitle("Tap to select") // image selection title
.single() // single mode
// multi mode (default mode)
.limit(10) // max images can be selected (99 by default)
.showCamera(true) // show camera or not (true by default)
.imageDirectory("Camera") // directory name for captured image ("Camera" folder by default)
// original selected images, used in multi mode
.start(12); // start image picker activity with request code
It is working I can see gallery.
onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ImageView imageview = (ImageView)findViewById(R.id.iv1);
if (requestCode == 12 && resultCode == RESULT_OK && data != null) {
ArrayList<Image> images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
// do your logic ....
imageview.setImageBitmap(images);//It is not working, I know it is not bitmap but how to set?
}
}
Finally how to set imageview ?
You can't set an image view to an arraylist of images, you can only set an image view to have one image as a source.
Also, looks like you are processing your images on the main thread, which is also not a good idea.
your images are in the Array, but you have to use them on multiple image views or a custom view that displays multiple images
private Bitmap getScreenshot(Image image) {
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * mWidth;
// ??????Bitmap???
Bitmap bitmap = Bitmap.createBitmap(mWidth + rowPadding / pixelStride, mHeight, Bitmap.Config.RGB_565);
bitmap.copyPixelsFromBuffer(buffer);
image.close();
return bitmap;
}
Image is resource rather than a image but you can use above API to get bitmap by using ByteBuffer. Pass images.get(position) in getScreenshot(Image image). it'll return bitmap then simply set imageView.setImageBitmap(bitmap) Example link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.