【发布时间】:2016-03-11 11:18:58
【问题描述】:
我正在做应用程序来将过滤器应用于图像。我从 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(0, 0, imageView.getWidth(), imageView.getHeight(), 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);
}
我尝试更改 GlSurfaceView 的大小并以此消除黑条,但它一直都是“match_parent”。 (我正在准备 ImageView 的宽度和高度参数)
ViewGroup.LayoutParams layoutParams=mEffectView.getLayoutParams();
layoutParams.width=mImageViewWidth;
layoutParams.height=mImageViewHeight;
mEffectView.setLayoutParams(layoutParams);
我还尝试在创建位图时添加一些偏移量,但它什么也没做,或者破坏了图像。 我该怎么做才能摆脱黑条? (他们也可以从侧面) 谢谢。
【问题讨论】:
标签: android android-layout android-bitmap glsurfaceview