我在onDrawFrame里面呼叫glReadPixels獲取像素點陣列,結果是資料錯誤,全是-16777216,導致截圖后顯示黑屏,其它手機(小米,魅族,ov等)呼叫glReadPixels方法后都是獲取到正確的像素點,顯示正常,
private Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, GL10 gl) {
int bitmapBuffer[] = new int[w * h;
int bitmapSource[] = new int[w * h;
IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
intBuffer.position(0);
try {
gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.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) & 0xffff0000;
int pixel = (texturePixel & 0xff00ff00) | red | blue;
bitmapSource[offset2 + j] = pixel;
}
}
} catch (GLException e) {
LogManager.e(TAG, "GLException: " + e.toString());
return null;
}
LogManager.e(TAG, "bitmapBuffer: " + Arrays.toString(bitmapBuffer));
LogManager.e(TAG, "bitmapSource: " + Arrays.toString(bitmapSource));
return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
}
uj5u.com熱心網友回復:
https://blog.csdn.net/androidwubo/article/details/100927784轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/84484.html
標籤:Android
上一篇:關于QT 段錯誤的問題
下一篇:統計無頭結點單串列中資料的個數
