I have a imageview that I want to change the color based on a user choice
From examples on the internet I see the only way to really do this is by going through and modifying each pixel… however it seems to be EXTREMELY slow
if I add this into my code, it takes long enough that it prompts the user to force close or wait
for(int i =0 ; i < mBitmap.getHeight(); ++i)
{
for(int g = 0; g < mBitmap.getWidth(); ++g)
{
}
}
What is the best way to change the color of the image?
The Image is a small image 320×100 and is mostly transparent with a small image in the inside, the small image I want to change the color of
The Problem lies in using
getPixel(x,y). Grabbing each pixel one by one is a very slow process. Instead usegetPixelsIt’ll return you an array of integers with the pixel values (and operate on that array and then use
setPixels) and it will be faster (although requires more memory)For a small image this method will do. Stride is equal to the image width.