Get and set the bitmap color chart in android

I have a bunch of small two-color PNG images, and I would like to effectively change one of the two colors to the other. Say RED => BLUE .

I know that I can either Bitmap.setXfermode over each pixel or use Bitmap.setXfermode to do this, but it feels like a big waste on such a simple problem. I want to access the file header and directly change it in the color table. This means that png: indexed http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap :

Note. Raster files can be automatically optimized using lossless compression using the aapt tool. For example, PNG with a true color that does not require more than 256 colors can be converted to an 8-bit PNG with a color palette. This will result in image quality, but less memory is required. Therefore, be aware that binary image files located in this directory may change during assembly. If you plan to read the image as a bitstream to convert it to a bitmap, instead place the images in the res / raw / folder folder where they will not be optimized.

Files placed in the "project" are indexed png images, so I know for sure that they are really indexed and have a color table. Should I read files as binary data and manipulate before I create a Bitmap object? I would prefer it if it weren’t, but instead there is some kind of hidden Bitmap.switchColor ( Col1, Col2 ); which will do just that, because I want to be able to switch back or to the third color.

Please, only answers to android and not general, as I am only looking for how to do this in android using Android classes.

Thank you in advance

+4
source share

Source: https://habr.com/ru/post/1338942/


All Articles