Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent bitmap too large to be uploaded into a texture android

I need to display original image in full screen in gallery form. For thumb it will be work perfectly and when I try to display that image in full screen with original source it will not be able to display. In most cases if the image resolution is greater then 2000 then it will display error bitmap too large to be uploaded into a texture android.

I want to prevent this, I have search google but not getting any answer regarding this.

like image 339
Pratik Avatar asked Mar 25 '14 11:03

Pratik


2 Answers

I came across the same problem and came up with a one liner solution for this problem here:

Picasso.with(context).load(new File(path/to/File)).fit().centerCrop().into(imageView);
like image 177
Phileo99 Avatar answered Sep 24 '22 16:09

Phileo99


i just created a if else function to check if the image is bigger than 1M pixels here's the sample code:

public void onActivityResult(int requestCode, int resultCode, Intent data) {

   if (resultCode == RESULT_OK) {

     if (requestCode == SELECT_PICTURE) {

        Uri selectedImageUri = data.getData();
        selectedImagePath = getPath(selectedImageUri);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;

        Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath);
        int height = bitmap.getHeight(), width = bitmap.getWidth();

        if (height > 1280 && width > 960){
            Bitmap imgbitmap = BitmapFactory.decodeFile(selectedImagePath, options);
            imageView.setImageBitmap(imgbitmap);

            System.out.println("Need to resize");

        }else {
            imageView.setImageBitmap(bitmap);
            System.out.println("WORKS");
        }
like image 29
Gilbert92 Avatar answered Sep 21 '22 16:09

Gilbert92