3

I have converted a JPEG image to an array of RGB color values through BitmapFactory.decodeStream and this code:

picw = selectedImage.getWidth();
pich = selectedImage.getHeight();

int[] pix = new int[picw * pich];

selectedImage.getPixels(pix, 0, picw, 0, 0, picw, pich);
int R, G, B;

for (int y = 0; y < pich; y++) {
        for (int x = 0; x < picw; x++) {
            int index = y * picw + x;
            R = (pix[index] >> 16) & 0xff;
            G = (pix[index] >> 8) & 0xff;
            B = pix[index] & 0xff;
            pix[index] = (R << 16) | (G << 8) | B;
        }
    }

Now, how do I convert this array back into an image?

2

1 Answer 1

6

you can use the static method Bitmap.createBitmap. E.g.

Bitmap bmp = Bitmap.createBitmap(pix, picw, pich, Bitmap.Config.ARGB_8888)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.