Android :: RuntimeException: Canvas: Trying To Use A Recycled Bitmap ..
Aug 22, 2009
I am getting the following logs when i am changing the wallpaper for Homescreen. Even i am recycling the bitmap is done when the wallpaper changes in OnWallpaperChanged(). Still i m getting the bellow error.
I am running into a problem with bitmaps on an Android application I am working on. What is suppose to happen is that the application downloads images from a website, saves them to the device, loads them into memory as bitmaps into an arraylist, and displays them to the user. This all works fine when the application is first started. However, I have added a refresh option for the user where the images are deleted, and the process outlined above starts all over.
My problem: By using the refresh option the old images were still in memory and I would quickly get OutOfMemoryErrors. Thus, if the images are being refreshed, I had it run through the arraylist and recycle the old images. However, when the application goes to load the new images into the arraylist, it crashes with a "Trying to use recycled bitmap" error.
As far as I understand it, recycling a bitmap destroys the bitmap and frees up its memory for other objects. If I want to use the bitmap again, it has to be reinitialized. I believe that I am doing this when the new files are loaded into the arraylist, but something is still wrong. Any help is greatly appreciated as this is very frustrating.
My loadMap() method generate a canvas.throwIfRecycled exception when i try to load a new map. When i start the game, the initial map loads and work fine though, its only when i try to load a new map that i get the exception ..
How can i "reset" canvas and the bitmap i use to draw into, so i can startover fresh with them ? here's what i use to create and draw my maps:
So basicaly once i created and used picDest and canvas, i cannot figure how to reset it all for when i want to load a new map..
I want to get the current bitmap associated with my canvas so I can perform operations on it. I can't see how to do this though.
I've seen some examples where you create a bitmap and set the canvas to use this bitmap, so obviously you can then access it later, but I'm using the canvas returned from a SurfaceHolder so there's no constructor.
For instance, examples often show this kind of thing:
So at this point I can see bmp.
In my case, the canvas is obtained by:
So how can I get the bitmap for c?
In short, my aim is to capture the current canvas contents where I have drawn "stuff", and make a copy of it, reversed, to put underneath. Like a reflection. The example of this that I found performed it all via bitmaps, so I assumed I needed to somehow capture the current canvas to a bitmap to then use it.
I am starting to develop a game. Right now I got a sprite animation going when a player moves across using sprite sheet. In my sprite sheet the character is always facing the same way, left. Now if I want the character to move right, I want it to be facing right. So is there a quick way in android to invert the bitmap after it has been loaded in? Or do I have to create sprite sheet for character facing right?
I want to draw a bitmap on a canvas with bigger size than it is. I can use canvas.drawBitmap(bitmap, null, destRect, null); but that gives a poor quality, as the result is pixelated, if the source image is sightly smaller than the destination rectangle. How can i draw my bitmap using bilinear or bicubic resampling?
At canvas there are many methods (canvas.rotate (35); canvas.drawBitmap (myBitmap, x, y, null); and many other things), but the method of mirror reflexion of image is absent (or I have not found it). At Bitmap too not that is not. Is it possible to reflect horizontally on canvas the image given Bitmap?
As we know, we can rotate a bitmap through 2 ways. The 1st way is: Matrix mt = new Matrix(); mt. postRotate (degree);Bitmap bitmap = CreateBitmap(src, 0, 0, w, h, mt, true); canvs.drawBitmap(bitmap, 0, 0, paint); In this way, we always need create new bitmap for every rotation, it is not good way for high performance game or app.The 2nd way is: canvas.save(); canvas.rotate(degree); canvas.drawBitmap(bitmap, 0, 0, paint); canvas.restore();In this way, we avoid creating new bitmap frequently, but the rotation bitmap is distortion, the bitmap quality is worse than first way.So, Is there 3rd way to rotate bitmap with high performance and good quality? Your any comments are really appreciated!
I have a very large image and I only want to display a section the size of the display (no scaling), and the section should just be the center of the image. Because the image is very large I cannot read the entire image into memory and then crop it. This is what I have so far but it will give OutOfMemory for large images. Also I don't think inSampleSize applies because I want to crop the image, not lower the resolution.
Uri data = getIntent().getData(); Input Stream is = getContentResolver().openInputStream(data); Bitmap bitmap = BitmapFactory.decodeStream(is, null, null);
I am 1) taking a picture and 2) then draw another Bitmap on top of it 3) then I store it
I am doing it as follows and it works on the emulator.
On the device I get a OutOfMemoryError: bitmap size exceeds VM budget android.graphics.Bitmap.nativeCopy(Native Method) android.graphics.Bitmap.copy(Bitmap.java:199) in the line copy the Bitmap to get a mutable Bitmap.
What I am asking:
a) Is there a better way to do what I am doing? 1) take a picture 2) draw another Bitmap on top of it 3) then I store it
b) What is the best way to create a mutable Bitmap from the picture I just took with the camera?
In my app, resolution is not an issue. If it works better for small photos that would be fine.
My goal is the draw a bitmap onto another bitmap but rotated 90 degress. whats the most efficient way to do that. My current method is as follows which is horribly bad because it creates a new bitmap every time.
I'm trying to add ScoreNinja, the global high score system, to my Android game, and it works fine when I load it on my phone, but when I release it into the wild, I got crash reports saying: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
I would like to do some tests on SlidingDrawer however i always found RuntimeException when SlidingDrawer.onMeasure is called i check the code and think the exception is caused by unspecified MeasureSpec
so i would like to ask how to setup the MeasureSpec in SlidingDrawer?
This code works fine if I move the findViewById call in to the Activity. Any hints as to why it doesn't work from inside the LearningView class? I've tried moving the TextView inside the com.example.LearningView tag but no joy. I'd prefer to get the TextView from within the SurfaceView subclass as I feel it's more logical to treat the TV as a "child" of the SV.
This is a contrived example I wrote to figure out the problem in a larger application, but the gist of it is the same, and the stack trace is basically the same.
For what it is worth, the findViewById call is returning null, which obviously threw NullPointerExceptions in some attempts to fix this.
As you can probably gather from my attempts I'm flying blind on this one.
I get the following error in logcat: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_height attribute. Can you please tell me which xml file that I am missing? And it said 'binary xml', does it mean it is actually line 26 in my file? or it is line 26 in the file after it compiles to be a binary xml file?..........
I wrote an android app and so far it works perfect except for on one phone. It is the exact phone that I have with 2.2 on both phones and mine works perfect. The other phone is getting force close all the time but only when opening an activity that queries my image DB and tries to show a gallery. Every activity crashes in the same place, the viewimages. At first I thought it was the intent that was doing it but one of the activitys does not have the intent, it opens the images below the gallery. This works on the emulator, on my moto droid and on a few other different droids. Here is the code for the gallery and my bitmap decoder.
I want to draw a shape(many circles particularly) into a Specific Bitmap. I have never used canvas / 2D graphs etc. As i see it i create a Drawable put the bitmap in it then "canvas-it" to the shapes i want etc.
I'm calling Debug.startMethodTracing("fnord") and I'm getting a java.lang.RuntimeException: file open failed message. It looks like I'm supposed to have the android.permission.WRITE_EXTERNAL_STORAGE permission set. But how do you set that permission when you're debugging through Eclipse? Aren't permissions normally set at install time (which doesn't happen in a normal way when you're debugging)?