I am having problems displaying images on Android. I want to scale small PNG images between arbitrary sizes of about 10-100% of their original size.
I created a sample image to demonstrate the problem and exacerbate the unusual behavior that I observe on a scalable Android device:
The above image is a screenshot from an Android device with annotations added. I also added the same images in the second column on the left side, showing how they are rendered using linear scaling using "GIMP" (GNU image manipulation program).
The main image consists of a red and blue pixel checkerboard pattern background. Against this background, I drew a few yellow lines 1px wide and pretty thin green text. The image is 288x288 pixels.
When scaling an image to 1/3 of its original size, Android seems to just capture one of nine pixels, throwing away all the rest of the data. As a result, some of the yellow lines completely disappear. Notably, the checkerboard pattern remains intact (which is simply the result of using every third pixel).
When scaling an image to a size of almost 50% of its original size, for example 142x142 or 143x143, the scaling device creates quite large anomalies / artifacts on the image.
At a size of 50% (144x144), the image looks right.
The test image displays the worst scalability image, but the "normal" PNG image images are also very influential. Between 10-33% or so, images are incorrectly oversampled and thus look extremely โrasterโ. And some larger images have very strange anomalies in them at certain sizes.
If someone knows how to disable this strange behavior when scaling, even at the cost of execution, I would really like to know about it. This, of course, can be solved by writing an algorithm that works directly on the pixels of the bitmap images, but I hope this is not the only option.
It should also be noted the fact that all work with images is performed using ARM_8888 Bitmap.Configs. I tried to manipulate the image size by setting maxwidth / maxheight in ImageViews using Bitmap.createScaledBitmap () and using Bitmap.createBitmap with a matrix. All attempts have the same result. Bitmap filtering is enabled.
Thanks again for any suggestions!