user5653405
user5653405

Reputation: 21

How to encode multiple images in array android studio

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_PICKER
            && resultCode == RESULT_OK && data != null) {

        // Uri FilePath = data.getData();

        images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < images.size(); i++) {
            sb.append(images.get(i).getName() + "\n");
            imageFile = new File(images.get(i).getPath());
            fileList.add(imageFile.getAbsoluteFile());
            bitmap = BitmapFactory.decodeFile(fileList.get(i)+"");

        }

        // System.out.println("Images :" + bitmap);

        tvtest.setText(sb.toString());
    }
}

Upvotes: 0

Views: 969

Answers (1)

szholdiyarov
szholdiyarov

Reputation: 385

I think you mean "how to include multiple images in array".

You can use an ArrayList to store your bitmaps:

ArrayList<Bitmap> arrayListOfBitmaps = new ArrayList<Bitmap>();
for (int i = 0; i < images.size(); i++) {
    imageFile = new File(images.get(i).getPath());
    bitmap = BitmapFactory.decodeFile(fileList.get(i)+"");
    arrayListOfBitmaps.add(bitmap); // Add a bitmap
}

Or if you really want to use an array:

Bitmap[] bitmapArray = new Bitmap[10];

But please be careful with bitmaps. They can eat a lot of device resources which will lead to OutOfMemoryError.

Upvotes: 1

Related Questions