Android Low image quality / altered image when using glReadPixels

﹥>﹥吖頭↗ 提交于 2019-12-08 00:41:13

问题


I've spend a lot of time trying to figure this out but can't see what I am doing wrong.

This is my original image

Image recaptured 5 times

Recapturing the image multiple times clearly shows that there is something not right. Capturing it once is just ok but twice is enough to clearly see the difference.

I found these similar issues on stackoverflow:

Bitmap quality using glReadPixels with frame buffer objects

Extract pixels from TextureSurface using glReadPixels resulting in bad image Bitmap

(sorry limited to links I can add)

Unfortunately none of the proposed suggestions/solutions fixed my issue. This is my code:

private Bitmap createSnapshot (int x, int y, int w, int h) {
    int bitmapBuffer[] = new int[w * h];
    int bitmapSource[] = new int[w * h];
    IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
    intBuffer.position(0);

    try {
        glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, intBuffer);
        int offset1, offset2;
        for (int i = 0; i < h; i++) {
            offset1 = i * w;
            offset2 = (h - i - 1) * w;
            for (int j = 0; j < w; j++) {
                int texturePixel = bitmapBuffer[offset1 + j];
                int blue = (texturePixel >> 16) & 0xff;
                int red = (texturePixel << 16) & 0x00ff0000;
                int pixel = (texturePixel & 0xff00ff00) | red | blue;
                bitmapSource[offset2 + j] = pixel;
            }
        }
    } catch (GLException e) {
        return null;
    }

    return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
}

I'm using OpenGL 2. For bitmap compression I am using PNG. Tested it using JPEG (quality 100) and the result is the same but slightly worse.

There is also a slight yellowish tint added to the image.

来源:https://stackoverflow.com/questions/41994649/android-low-image-quality-altered-image-when-using-glreadpixels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!