2
大家好〜我想讓屏幕顯示我們觸摸的像素是什麼顏色,然後我使用GLES20.glReadPixels如下。如logcat所示,無論我點擊哪個位置,它總是讀取0 0 0 0。我也根據屏幕的寬度和高度更改了索引,但仍然全部爲零。我知道這應該很容易,但我真的不知道如何解決它。有人可以幫我一把嗎?非常感謝!GLES20.glReadPixels在android中得到全零位
public String getFace(float angleX, float angleY, float positionX, float positionY){
String toast = "other";
int tempX = Math.round(positionX);
int tempY = Math.round(positionY);
ByteBuffer ss = ByteBuffer.allocate(4);
ss.order(ByteOrder.nativeOrder());
GLES20.glFlush();
//Get Screen's width and height
DisplayMetrics displaymetrics = new DisplayMetrics();
((Activity) getContext()).getWindowManager()
.getDefaultDisplay()
.getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
int X = tempX;
int Y = height-tempY;
//Here it's
GLES20.glReadPixels(X, Y, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ss);
byte b[] = new byte[4];
ss.get(b);
String key = "" + b[0] + " " + b[1] + " " + b[2] + " " + b[3];
Log.d("Color: ", key);
ss.rewind();
Log.d("DEBUG", "X:"+ X + " Y:" + Y);
Log.d("DEBUG", "w:"+ width + " h:" + height);
if (key = ' 1 0 0 1') {
toast = "Face Red";
} else {
toast = "other";
}
return toast;
}