Out of memory and OpenGL errors while manipulating two images on android
Hi: I have to images on two files (left and right) What I want to do is show them side by side in a ImageSwitcher. This is the function that returns the Drawable that I want to set in the 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()));
开发者_如何学Go 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);
}
I have two problems. If I use Config.ARGB_8888 I get out of memory errors. So I changed to RGB_565. However this will reduce the qualities of the images. Is there anyway around this?
Second even I change the config settings I get the following console messages:
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
And I obviously never see the generated Image. So I want to know what I'm doing wrong?
On a side note the first two images should be shown when an activity is started so the code above is called on the OnResume Method of the activity. Can any one tell me why this method is executed twice (as it is obvious by the printout)? Because maybe my out of memory errors have to do with this...
Thanks for any help in advance.
Maybe you where struck by the hardware acc limit metioned here
http://groups.google.com/group/android-developers/browse_thread/thread/2352c776651b6f99
It's not exactly an answer, but maybe it's help someone. I circumvented the problem by using two side by side image views. If all you want to do is see the images (which was my case) then To get the images to touch in the border I used fitScaleType fitend for the image on the left and fitstart for the image on the right (Landscape mode was fixed in my case).
精彩评论