更改位图的inSampleSize
作者:互联网
我正在从glsurfaceview创建位图并将其添加到arraylist,但是当我从glsurfaceview创建位图时会出现内存不足错误
码:
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"
在清单文件中.
中学,如果那没有帮助你看那https://stackoverflow.com/a/17839597/2956344
我也建议您了解GLSufaceView的最大纹理大小,以编程方式检查位图分辨率的限制.
Get Maximum OpenGL ES 2.0 Texture Size Limit in Android
附言我想您会找到有关使用GL10的信息.
标签:bitmapfactory,opengl-es,bitmap,glsurfaceview,android 来源: https://codeday.me/bug/20191029/1960129.html