1
美好的一天。ANDROID:将OpenGL onDraw转换为位图,然后在ImageView中显示位图
我在自己的imageView中显示来自openGL的位图时出现问题。
首先,我创建的3D OpenGL的对象中(像立方体,球体等)
然后,我的openGL的视图的onDraw转换为位图(我用这个代码)
public static Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, GL10 gl)
throws OutOfMemoryError {
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) & 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);
}
嗯,它捕获了onDraw的视图并将其转换为位图,但我需要的是将openGL作为后台进程,将其视图转换为位图,在主要活动的imageview中显示位图。
我删除了
setContentView(ourSurfaceView)
我mainActivity
但删除它,改变我的layout.xml 位图我从openGL的创建后不能正常工作。 (对不起,我的英语)
THANKs in advanced。 :)