位图的inSampleSize值改变

3

我正在从glsurfaceview创建位图并将其添加到arraylist中,但是当我从glsurfaceview创建位图时,它会出现outofmemory error错误。

代码:

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);
}

对于分辨率较大的设备(例如三星Galaxy S4),我的应用程序会崩溃。

我想知道如何设置该位图的inSampleSize。

1个回答

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接