I have a bitmap which i am loading each pixel to array. Later i run through each array pixel data and check if the color is RED and change it to BLACK. So if it is a 1024x1024 image, i have to go through a array of 1048576 length. Is there any faster way to process this. Any kind of advice to improve performance is welcome. I basically need to check for a color in image and change it. Below is my code sample.
int[] allpixels = new int[myBitmap.getHeight() * myBitmap.getWidth()];
myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0,
myBitmap.getWidth(), myBitmap.getHeight());
for (int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) {
if (allpixels[i] == fromColor) {
allpixels[i] = toColor;
}
}
Bitmap bitmapCopy = myBitmap.copy(myBitmap.getConfig(), true);
bitmapCopy.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0,
myBitmap.getWidth(), myBitmap.getHeight());