I'm writing an Android instrumentation test case that should trigger an OutOfMemoryError in a class that uses an ImageDecoder. Since I don't want to include a huge test image (>100MB) in the repository, I'm trying to generate it in the test case.
I've generated, and stored in the test app's cache, a raw Bitmap (5000x5000 px) that weighs in at 96MB but the ImageDecoder requires an encoded image. Attempting to do the same and compress it with the highest quality results in a JPG of 1MB and a PNG of 5MB. At the moment I'm just generating random colors (ARGB) on the 5000x5000 bitmap, but that was too easy for the encoders.
Is there a way to create an encoded image, but compress it as little as possible? Or is there a way to "beat" the compression algorithm to get a much larger file? A (weak) assumption I have is that I must not increase width and height, and may need to keep it at 4096x4096, see this. Is there some other way I can generate large encoded images on the fly?
The end goal is to trigger the OutOfMemoryError and then test if for example, setting the sampleSize, would let the class handle very large files and not run out of memory.