嗨:我必须对两个文件(左和右)进行图像处理我想要做的是在ImageSwitcher中并排显示它们。这是返回我想在imageswitcher中设置的Drawable的函数:
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方法上调用上面的代码。任何人都可以告诉我为什么这个方法被执行两次(打印输出很明显)?因为也许是我的内存错误 与此有关...
感谢您提前提供任何帮助。
答案 0 :(得分:2)
也许你对这里提到的硬件限制感到震惊
http://groups.google.com/group/android-developers/browse_thread/thread/2352c776651b6f99
答案 1 :(得分:0)
这不完全是答案,但也许对某人有所帮助。我通过使用两个并排的图像视图来规避问题。如果您只想看图像(这是我的情况)那么为了让图像在边框中触摸我使用fitScaleType fitend为左边的图像和fitstart为右边的图像(横向模式是固定的我的情况)。