0

I am trying to load very high resolution image (15000 x 8438) with glide and saving it as bitmap. I am using glide for that. The problem is that when I try to save bitmap image to file I get black image instead of actual image.

I feel maybe this is because of very high resolution. After converting to bitmap these values I have obtained: width 15000 height: 8438 getAllocationInBytes : 506280000.

I tried to downscale image with .downsample(DownsampleStrategy.AT_MOST) but image is still 15000 x 8438. The code I am using is:

Glide.with(this).asBitmap()

                .load(imagePath)
                .downsample(DownsampleStrategy.AT_MOST)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .skipMemoryCache(true)
                .into(FileTarget(someFile, Bitmap.CompressFormat.JPEG, 90) {}

Can someone please help, how can I down scale the image and save it to the file. Also is it possible to achieve it with glide ?

Thank you.

  • IMHO, Glide is not really designed for your scenario. Perhaps you should just download the image directly, such as [via OkHttp](https://stackoverflow.com/a/29012988/115145). – CommonsWare May 07 '21 at 18:10

1 Answers1

0

To make downsample works as expected, you probably forgot to add the maxWidth and maxHeight override:

....
.downsample(DownsampleStrategy.AT_MOST)
.override(maxWidth, maxHeight)
...
Tomas
  • 4,652
  • 6
  • 31
  • 37