High resolution image not display in ImageView Android

后端 未结 5 990
小鲜肉
小鲜肉 2021-01-07 03:13

I am displaying an image in full screen mode,but whenever going to display large image then nothing display in the image view. Below code try to resize bitmap but got same r

5条回答
  •  情话喂你
    2021-01-07 04:11

    You solve your problem in Fragment Add method in adapter

     public Bitmap decodeImage(int gridViewImageId) {
        try {
            // Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeResource(mContext.getResources(), gridViewImageId, o);
            // The new size we want to scale to
            final int REQUIRED_SIZE = 100; // you are free to modify size as your requirement
    
            // Find the correct scale value. It should be the power of 2.
            int scale = 1;
            while (o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE)
                scale *= 2;
    
            // Decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeResource(mContext.getResources(), gridViewImageId, o2);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return null;
    
    }
    

    and add this line

    imageViewAndroid.setImageBitmap(decodeImage(gridViewImageId[i]));
    

提交回复
热议问题