首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在安卓系统上操作两张图片时出现内存不足和OpenGL错误

问在安卓系统上操作两张图片时出现内存不足和OpenGL错误
EN

Stack Overflow用户
提问于 2011-06-19 20:20:00
回答 2查看 1.2K关注 0票数 0

嗨:我必须在两个文件(左和右)上显示图像,我想做的是在ImageSwitcher中并排显示它们。这是返回我想要在imageswitcher中设置的可绘制内容的函数:

代码语言:javascript
复制
public Drawable getImage(String left, String right){
    System.err.println("Decoding both images");
    Bitmap Left = BitmapFactory.decodeFile(left);
    Bitmap Right = BitmapFactory.decodeFile(right);
    int height = Math.max(Left.getHeight(),Right.getHeight());
    int width = Left.getWidth() + Right.getWidth();
    Bitmap result = Bitmap.createBitmap(width,height,Config.RGB_565);       
    System.err.println("Creating the canvas");
    Canvas bothImages = new Canvas(result);
    System.err.println("Drawing both images beside each other");
    bothImages.drawBitmap(Left, 0f, 0f, null);
    bothImages.drawBitmap(Right, Left.getWidth(), 0f, null);
    System.err.println(Integer.toString(bothImages.getWidth()) + " x " + Integer.toString(bothImages.getHeight())); 
    bothImages.rotate(90f);
    System.err.println(Integer.toString(bothImages.getWidth()) + " x " + Integer.toString(bothImages.getHeight()));
    System.err.println("returning Drawable Left");
    return new BitmapDrawable(result);
}

我有两个问题。如果我使用Config.ARGB_8888,我会出现内存不足的错误。所以我改成了RGB_565。然而,这会降低图像的质量。有没有什么办法解决这个问题呢?

其次,即使我更改了配置设置,我也会收到以下控制台消息:

代码语言:javascript
复制
06-19 09:16:23.760: WARN/System.err(26218): Attempting to show /mnt/sdcard/Work/.temp/0000.jpg
06-19 09:16:23.760: WARN/System.err(26218): Decoding both images
06-19 09:16:24.510: WARN/System.err(26218): Creating the canvas
06-19 09:16:24.510: WARN/System.err(26218): Drawing both images beside each other
06-19 09:16:24.530: WARN/System.err(26218): 2560 x 1971
06-19 09:16:24.530: WARN/System.err(26218): 2560 x 1971
06-19 09:16:24.530: WARN/System.err(26218): returning Drawable Left
06-19 09:16:24.570: WARN/OpenGLRenderer(26218): Bitmap too large to be uploaded into a texture
06-19 09:16:24.850: WARN/OpenGLRenderer(26218): Bitmap too large to be uploaded into a texture
06-19 09:16:24.870: WARN/System.err(26218): Inside On resume
06-19 09:16:24.870: WARN/System.err(26218): About to set up animations
06-19 09:16:24.870: WARN/System.err(26218): On resume Done
06-19 09:16:24.870: WARN/System.err(26218): Attempting to show /mnt/sdcard/Work/.temp/0000.jpg
06-19 09:16:24.870: WARN/System.err(26218): Decoding both images
06-19 09:16:25.610: WARN/System.err(26218): Creating the canvas
06-19 09:16:25.610: WARN/System.err(26218): Drawing both images beside each other
06-19 09:16:25.640: WARN/System.err(26218): 2560 x 1971
06-19 09:16:25.640: WARN/System.err(26218): 2560 x 1971
06-19 09:16:25.640: WARN/System.err(26218): returning Drawable Left
06-19 09:16:25.660: WARN/OpenGLRenderer(26218): Bitmap too large to be uploaded into a texture
06-19 09:16:25.690: WARN/OpenGLRenderer(26218): Bitmap too large to be uploaded into a texture

很明显,我从未见过生成的图像。所以我想知道我做错了什么?

另外,在启动活动时应该显示前两个图像,以便在活动的OnResume方法上调用上面的代码。谁能告诉我为什么这个方法被执行了两次(从打印输出中可以明显看出)?因为也许我的内存不足错误与此有关...

提前感谢您的帮助。

EN

回答 2

Stack Overflow用户

发布于 2011-11-07 20:59:57

票数 2
EN

Stack Overflow用户

发布于 2011-06-21 22:03:11

这不是一个确切的答案,但它可能是帮助某人。我通过使用两个并排的图像视图绕过了这个问题。如果你想要做的就是查看图片(我的例子就是这样),那么为了让图片接触到边框,我对左边的图片使用了fitScaleType fitend,对右边的图片使用了fitstart (我的例子修正了横向模式)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6402307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档