0

I am getting this array of images using Pix image picker library, I just want to display the first image from an array into image view.no idea how to do it. here is my code

public void uploadImages(View view) {
   Pix.start(Upload_ad.this,
            100,
            10);

}
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK && requestCode == 100) {
             ArrayList<String> returnValue = data.getStringArrayListExtra(Pix.IMAGE_RESULTS);

           for (String path: returnValue)
            {

                String base64 = getBase64FromFile(path);
                encodedImageList.add(base64);
            }

        }
    }

2 Answers 2

2

You can set base64 string from your encoded list as below

if (encodedImageList != null) {
    byte[] decodedString = Base64.decode(encodedImageList.get(0), Base64.DEFAULT);
    Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 
    yourimageview.setImageBitmap(decodedByte);
}
Sign up to request clarification or add additional context in comments.

4 Comments

ok for now working for both but app crashes when i select single picture after applying this code. if (encodedImageList.get(1) != null) { //2nd image byte[] decodedString2 = Base64.decode(encodedImageList.get(1), Base64.DEFAULT); Bitmap decodedByte2 = BitmapFactory.decodeByteArray(decodedString2, 0, decodedString2.length); imageView2.setImageBitmap(decodedByte2); }
debug and check if your encodedImageList has elements that you are accessing.
it has element in encodedImageList.get(1) ,and 2nd image also set to 2nd image view but the problem occurs when i select single image.
It would be good if you can post it as separate question with code and error stacktrace.
0

You can manage somehow by:

ArrayList<String> returnValue = data.getStringArrayListExtra(Pix.IMAGE_RESULTS);
if(returnValue != null && !returnValue.isEmpty()) {
    String firstImage = returnValue.get(0);
    if(!TextUtils.isEmpty(firstImage)) {
        // here you will find first-image
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.