If I want to set the background resource of a view with a large PNG,
what is the best way to do it? Right now I just call
setBackgroundResource with the id of the resource eg.
R.drawable.wallpaper_news. Is there a better way to do it using
decodeByteArray? I have a couple of views to set the background for.
Which method is it best to do it in? Is dispatchDraw a good place?

Rohit


On Jan 13, 7:27 pm, nickthecook <nickthec...@gmail.com> wrote:
> Interesting!
>
> I'm usually able to load these images without a problem. Maybe 1 in 5
> loads fails. Since they are all the same size, I would expect all
> calls to fail like this, or none, but that number is definitely not a
> coincidence.
>
> Anyway, I'm now using the version of decodeByteArray that takes
> options with inSampleSize = 2, and can't get it to crash no matter how
> many images I try to process in a row, so the problem is gone for now,
> at least.
>
> Thanks for the insight!
>
> On Jan 13, 8:21 am, blindfold <seeingwithso...@gmail.com> wrote:
>
> > Sounds like your have ~300 KB JPEG-compressed images at the standard
> > G1 resolution of 2048 * 1536. At 2 bytes per pixel (using RGB_565 or
> > ARGB_4444 format) this will in your phone expand into 2048 * 1536 * 2
> > = 6291456 bytes uncompressed. That's a sizable chunk of memory.
>
> > Regards
>
> > On Jan 11, 4:29 pm, nickthecook <nickthec...@gmail.com> wrote:
>
> > > I'm still seeing this problem as well. I can boot my phone, start my
> > > app, load a single image (~300k) and have this error. I'm loading
> > > images with the BitmapFactory.decodeByteArray() method, which calls
> > > BitmapFactory.nativeDecodeByteArray().
>
> > > What is interesting is that after I added a background thread to my
> > > app to load and process images, I had a bug where changing the
> > > orientation of the screen caused another thread to be started. As soon
> > > as two of my threads were in BitmapFactory.nativeDecodeByteArray() at
> > > the same time, this method would attempt to allocate over 6MB of
> > > memory, and I would get the error.
>
> > > E/dalvikvm-heap( 1204): 6291456-byte external allocation too large for
> > > this process.
>
>
--~--~---------~--~----~------------~-------~--~----~
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