"  *But there is one big question...why does recycling the bitmaps after
their last use still result in a force close, saying that I tried to use
them AFTER they were recycled?  *"

We don't have enough of your code. But suppose you have this code executed:


Bitmap bitmap1 = new BitmapFactory.decode.....();
...
...
Bitmap bitmap2 = bitmap1;
...
...
bitmap1.recycle();
...
...

bitmap2.getWidth(); // kaboom: You're using an already recycled bitmap.

In other words, you're assigning the same Bitmap instance to more than one 
variable or field and you are using one variable to recycle() the bitmap. 
If the code handling the other variables/fields doesn't know about the fact 
that recycle() already has been called, handling these other 
variables/fields may result in a force close (bitmap already recycled). You 
can call 'bitmap.isRecycled()' if  you don't keep track of it yourself.



On Thursday, April 19, 2012 9:38:28 AM UTC-4, Spooky wrote:
>
> On Thu, Apr 19, 2012 at 06:25:12AM -0700, Streets Of Boston wrote:
> > First, ignore this sentence below from my previous answer entirely:
> >  "Save the byte[] data from the camera into file directly (this is your 
> > JPG file)."
> > (It was a left-over chunk of my initial answer)
>
> Ah, that explains it.  :-)
>
> > The 'byte[] data' still takes up memory, because the caller (the Android 
> > SDK code that calls the onPictureTaken) still has hold of this 
> byte-array. 
> > Setting data=null won't free that memory because only your code release 
> > reference to it, not the caller's code.
>
> Ohhh, yeah, I hadn't thought about that.  Damn.  Not much I can do about
> that, then.
>
> > You can save the raw data of the camera's Bitmap (the bitmap returned 
> from 
> > decodeByteArray) by calling Bitmap.getPixels a few times (saving the raw 
> > data in chunks)  or by calling Bitmap.copyPixelsToBuffer.
>
> That's basically what I came up with.  This basically just flashed across
> my brain this morning, and is a combination of ideas I'd been looking at.
> It goes something like this:
>
> 1) if the device can handle this much, convert the original byte[]
>    array to a bitmap (easy).  if not, re-size, notify the user, and
>    deal with it.
>
> 2) assuming we got past #1, split the file into vertical chunks using
>
>    Bitmap chunk1; // so each can be recycled immediately after use
>    Bitmap chunk2;
>    ....
>    Bitmap chunkn;
>    
>    chunk1 = createBitmap(src, 0, 0, width, height/n);
>
>    // save the chunk to a raw data file here
>
>    chunk1.recycle(); chunk1 = null;
>
>    and so on for all n chunks.
>
> 3) recycle the original photo image;
>
> 4) create the bitmap for the filter and repeat step 2 for it.
>
> 5) re-use the bitmap from 4 (or recycle it and make another new one)
>    for the combined image, then, one at a time, recover the saved
>    bitmap chunks and use paint/canvas to re-build them, and then
>    immediately recycle the chunk once it's no longer needed.
>
> 6) Save the new photo
>
> But there is one big question...why does recycling the bitmaps after
> their last use still result in a force close, saying that I tried to use
> them AFTER they were recycled?
>
> Oh, and steps 5 and 6 may need to be done in a new process, if I can
> figure out how to do that (or if someone here will point me to the
> appropriate reference in the dev guide).
>
> So, how does that sound?
>
> Thanks,
>    --jim
>
> -- 
> THE SCORE:  ME:  2  CANCER:  0
> 73 DE N5IAL (/4)        | Tux (E Cat):  DS B+Wd Y 6 Y L+++ W+ C++/C++ I+++
> spooky1...@gmail.com    | T++ A E H+ S V- F++ Q+++ P/P+ B++ PA+ PL SC---
> < Running FreeBSD 7.0 > | 
> ICBM / Hurricane:       | Tiggerbelle:  DS W+S+Bts % 1.5 X L W C+++/C+
>    30.44406N 86.59909W  | I+++  T A E++ H S++ V+++ Q+++ P  B++ PA++ PL+ SC
>
> Android Apps Listing at http://www.jstrack.org/barcodes.html
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to