Mungunbat Enkhbayar
Mungunbat Enkhbayar

Reputation: 181

how to get colors by glreadpixels?

I am trying to get a color of touch point on the screen in Android. but it shows me only RGB = (0, 0, 0) value. I have searched other sites. it said that i should add some codes below but it didn`t change anything.

getHolder().setFormat(PixelFormat.TRANSLUCENT);
setEGLConfigChooser(8,8,8,8,0,0);

so any advices would be appreciated thanks in advance.

ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4);
    PixelBuffer.order(ByteOrder.nativeOrder());
    PixelBuffer.position(0);
    int mTemp = 0;
    GLES20.glReadPixels(touchX, touchY, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, PixelBuffer);
    byte b[] = new byte[4];
    PixelBuffer.get(b);
    tmp = String.valueOf(String.format("RED : %d GREEN %d BLUE %d", PixelBuffer.get(0), PixelBuffer.get(1), PixelBuffer.get(2)));
    tmp += String.valueOf(String.format("RED : %d GREEN %d BLUE %d", b[0], b[1], b[2]));
    Log.e("COLOR", "R:" + PixelBuffer.get(0) + PixelBuffer.get(1) + PixelBuffer.get(2));

Upvotes: 1

Views: 2424

Answers (1)

Chau Chi Thien
Chau Chi Thien

Reputation: 31

Did you use openGL for draw screen or just normal application? If you use openGL then do you use OpenGL 2.0 or 1.x to draw your screen? Does you phone support openGLES 2.0? I can see they are not much device support it. You can check out http://code.google.com/p/libgdx/ source code, they have some example for getting FramBuffer Pixels.

For example "libgdx\extensions\gdx-tools\src\com\badlogic\gdx\tools\hiero\BMFontUtil.java" line 176.

Upvotes: 0

Related Questions