相关疑难解决方法(0)

"位图太大而无法上传到纹理中"

我正在将一个位图加载到ImageView中,并看到此错误.我收集此限制与OpenGL硬件纹理(2048x2048)的大小限制有关.我需要加载的图像是大约4,000像素高的捏缩图像.

我试过关闭清单中的硬件加速,但没有快乐.

    <application
        android:hardwareAccelerated="false"
        ....
        >
Run Code Online (Sandbox Code Playgroud)

是否可以将大于2048像素的图像加载到ImageView中?

android android-image android-imageview android-bitmap

149
推荐指数
9
解决办法
11万
查看次数

Android:位图的最大允许宽度和高度

我正在创建一个需要将大图像解码为位图的应用程序,以便在ImageView中显示.

如果我只是尝试将它们直接解码为位图,我会收到以下错误"位图太大而无法上传到纹理中(1944x2592,max = 2048x2048)"

因此,为了能够使用以下方法显示分辨率过高的图像:

Bitmap bitmap = BitmapFactory.decodeFile(path);

if(bitmap.getHeight()>=2048||bitmap.getWidth()>=2048){
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    bitmap =Bitmap.createScaledBitmap(bitmap, width, height, true);             
}
Run Code Online (Sandbox Code Playgroud)

这有效,但我真的不想像现在的if语句那样对2048的最大值进行硬编码,但是我无法找到如何获得设备位图的最大允许大小

有任何想法吗?

android bitmap

28
推荐指数
2
解决办法
3万
查看次数

在Android中获取最大OpenGL ES 2.0纹理大小限制

我试图在Android for OpenGL 2.0中获得最大的纹理大小限制.但是我发现只有当我在OpenGL上下文中时,下一条指令才有效,换句话说我必须有GL Surface和GL Renderer等,这是我不想要的.

int[] maxTextureSize = new int[1];
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
Run Code Online (Sandbox Code Playgroud)

所以我选择了下一个算法,它给了我最大的纹理大小,而不必创建任何表面或渲染器.它的工作正常,所以我的问题是,这是否适用于所有Android设备,如果有人能发现任何错误,以防万一.

public int getMaximumTextureSize()
{
    EGL10 egl = (EGL10)EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations …
Run Code Online (Sandbox Code Playgroud)

android textures opengl-es

8
推荐指数
1
解决办法
6762
查看次数

位图太大,无法在缩小后上传到纹理中

我做了一个有很大背景的应用程序.它在Nexus 7上完美运行,但在我的Galaxy Nexus上,背景消失了,并在logcat中给出了错误:位图太大而无法上传到纹理(...).

我已经阅读了这篇文章并使用了那里的代码.我用来设置背景的代码是这样的:

Display display = getWindowManager().getDefaultDisplay();
    width = display.getWidth();
    height = display.getHeight();


    //-------------------------------------------------------------------------------------------------------------

    ImageView achtergrond = (ImageView)findViewById(R.id.achtergrond);
    achtergrond.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.drawable.achtergrond, width, height));
} (...)

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
        int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options); …
Run Code Online (Sandbox Code Playgroud)

android bitmap android-imageview

2
推荐指数
1
解决办法
2556
查看次数