jack
jack

Reputation: 155

image too large to be displayed

I am building an app to load images from the gallery, so far it's working well for some images, but some images i keep getting the message " Bitmap too large to be uploaded into a texture (2988x5312, max=4096x4096) "

here is the code to display the bitmap.

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

        if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null)
        {
            Uri filePath = data.getData();
            try {
                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                Picasso.with(MainActivity.this).load(filePath).error(R.drawable.smile).into(imageView1);
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }

what can i do to fix this ? resize the image ? or check to see if the image is too big ? and what is the resolution acceptable for images here ?

Upvotes: 2

Views: 2837

Answers (2)

ErShani
ErShani

Reputation: 392

Picasso has good enough cache management features. you can resize image,

Picasso
.with(context)
.load(YOUR IMAGE PATH)
.resize(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
.into(imageView);

or you can scale down image.

 Picasso
.with(context)
.load(YOUR IMAGE PATH])
.resize(1920, 1080) // your desire ratio
.onlyScaleDown() // the image will only be resized if it's bigger than 6000x2000 pixels.
.into(imageView);

Upvotes: 2

You answered yourself, yes you have to scale your image, with picasso that's easy, anyway check this issue and the answer to check how to get the max texture size supported by a device.

Check this link to know how to resample images with picasso.

Upvotes: 3

Related Questions