0
我修改了this project,它使用GLSurfaceView和Effects来显示ViewPager,其中一些效果应用于图像。Android GLSurfaceView保存位图导致异常
此外,我创建了覆盖位图,该效果已应用后放置在每个图像上。
此时,该应用程序工作正常。但是现在我必须将显示的图像保存在文件中,当按下按钮时。
所以就用这样的代码:
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) {
e.printStackTrace();
return null;
}
return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
}
以获得位图。当按下按钮时,我调用这个方法:
protected void onClick() {
read = true;
mEffectView.requestRender();
}
迫使渲染,所以我生成位图,并将其保存在使用的AsyncTask的文件。 读取被用作onDrawFrame(GL10 gl)中的半焦以在我想要保存时只生成位图。
保存一张图片效果很好。当我保存的第二个,然后我改变页面,这个错误出现:
A/Bitmap: Failed to acquire strong reference to pixels
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 20475 (GLThread 9540)
的另一个问题是,叠加,虽然显示出来,不会被保存在图像中。 这是我如何应用它:
代
EffectFactory effectFactory = mEffectContext.getFactory();
overlayEffect = effectFactory.createEffect(EffectFactory.EFFECT_BITMAPOVERLAY);
overlayEffect.setParameter("bitmap", overlay);
影响应用
mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
overlayEffect.apply(mTextures[1], mImageWidth, mImageHeight, mTextures[2]);
随着mEffect保存图像时是唯一的效果看得见。
我在做什么错了?
编辑 我解决了最后一个问题:我发现,你必须发布和重新你每次使用的每一种效果对象被称为mEffectView.requestRender()。