我正在从 glsurfaceview 创建一个位图并将其添加到数组列表中,但是当我从 glsurfaceview 创建一个位图时它会出现 outofmemory 错误
代码:
Bitmap bitmap = createBitmapFromGLSurface(0, 0, mEffectView.getWidth(),
mEffectView.getHeight(), gl);
al_bitmaps.add(bitmap);
方法:
private 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);
}
对于分辨率更大的设备(例如 Samsung Galaxy S4),我的应用会崩溃。
我想知道如何设置该位图的 inSampleSize。
最佳答案
首先我会推荐给你使用
android:largeHeap="true"
在您的 list 文件中。
中学,如果这对您没有帮助,请看https://stackoverflow.com/a/17839597/2956344
我还建议您了解 GLSufaceView
的最大纹理大小,以便以编程方式检查位图分辨率的限制。
Get Maximum OpenGL ES 2.0 Texture Size Limit in Android
附言我想您找到了有关使用 GL10 的信息。
关于android - 更改位图的样本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24178863/