Search code examples
javaandroidbitmapbit-manipulationmutable

Android Bitmap Manipulation


Can you tell me what's wrong with this piece of code?

//bmp is a bitmap of already present image
int width=bmp.getWidth();
int height=bmp.getHeight();
int rgbval[]=new int[width*height];
bmp.getPixels(rgbval, 0, width, 0, 0, width, height);
rgbval=actual(rgbval);
Bitmap bmp2=bmp.copy(Bitmap.Config.ARGB_8888,true);
bmp2.setPixels(rgbval, 0, width, 0, 0, width, height);

actual is a function I have created to manipulate the rgb values of a bmp. By using debug functions of eclipse I have checked that it is working correctly , but when I try to recover rgb values of bmp2 , I don't get the manipulated values.


Solution

  • I think the problem is due to some android bug. I have manipulated the pixels of the bitmap and i needed the pixel values to exactly the same , but when i used setPixels to set the complete pixels of the bitmap it did not work. I found the solution by using

    index=0;
    for (int j = 0; j < height; j++)
       for (int i = 0; i < width; i++)
       {
        destBitmap.setPixel(i, j, pixelvalues[index]);
    
       }
    

    So if i set the pixel one by one instead of all at a time somehow it works!