Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android上操作两幅图像时出现内存不足和OpenGL错误_Android_Image Processing_Out Of Memory - Fatal编程技术网

在android上操作两幅图像时出现内存不足和OpenGL错误

在android上操作两幅图像时出现内存不足和OpenGL错误,android,image-processing,out-of-memory,Android,Image Processing,Out Of Memory,您好:我必须在两个文件(左侧和右侧)上显示图像。我要做的是在图像切换器中并排显示它们。这是返回要在imageswitcher中设置的可绘制图形的函数: public Drawable getImage(String left, String right){ System.err.println("Decoding both images"); Bitmap Left = BitmapFactory.decodeFile(left); Bitmap Right = Bitm

您好:我必须在两个文件(左侧和右侧)上显示图像。我要做的是在图像切换器中并排显示它们。这是返回要在imageswitcher中设置的可绘制图形的函数:

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。但是,这会降低图像的质量。这有什么关系吗

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

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方法上调用上面的代码。有人能告诉我为什么这个方法要执行两次吗(打印输出很明显)?因为可能是我的内存不足错误 与此有关


感谢您事先提供的帮助。

这不是一个确切的答案,但可能是帮助了某人。我通过使用两个并排的图像视图来避免这个问题。如果您只想看到图像(这是我的情况),那么为了让图像在边框中接触,我对左侧的图像使用fitScaleType fitend,对右侧的图像使用fitstart(在我的情况下,横向模式是固定的)。

可能您受到了此处所述硬件acc限制的影响