【问题标题】:Change inSampleSize of a Bitmap更改位图的SampleSize
【发布时间】:2014-08-02 10:50:09
【问题描述】:

我正在从 glsurfaceview 创建一个位图并将其添加到一个数组列表中,但是当我从 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。

【问题讨论】:

    标签: android opengl-es bitmap bitmapfactory glsurfaceview


    【解决方案1】:

    首先我会推荐给你使用

    android:largeHeap="true"
    

    在您的清单文件中。

    如果这对您没有帮助,请看https://stackoverflow.com/a/17839597/2956344

    我还建议您了解GLSufaceView 的最大纹理大小,以便以编程方式检查位图分辨率的限制。

    Get Maximum OpenGL ES 2.0 Texture Size Limit in Android

    附:我想你找到了有关使用 GL10 的信息。

    【讨论】:

      猜你喜欢
      • 2018-08-23
      • 1970-01-01
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 2011-02-13
      • 1970-01-01
      相关资源
      最近更新 更多