[android-developers] Re: Question around Bitmap loading

2011-09-02 Thread blew
So this is telling me all the "extra" memory that's being used up.
Any idea why it's labeled as  in the error message?
Doesn't seem to me to be very relevant.

Thanks for the answer, I'll keep that in mind.

On Aug 27, 9:38 pm, Streets Of Boston  wrote:
> Because the rest of your app is using memory as well.
> And you'd need 10 blocks of 1.5MBytes of *contiguous *memory.
> This may not be possible --> Out of memory error.

-- 
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


[android-developers] Question around Bitmap loading

2011-08-27 Thread blew
Hello fellow developers,

This is again, about the famous "external allocation too large for
this process" Out of Memory exception when loading Bitmaps into your
memory.
The problem revolves around the following error message:

1502400-byte external allocation too large for this process.
Out of memory: Heap Size=5123KB, Allocated=2481KB, Bitmap Size=11183KB
VM won't let us allocate 1502400 bytes

I've been doing some simple tests and I just can't seem to figure out
what the "Bitmap Size" means.

The bit of code which generates the above error is as follow:

I call the following line (nothing else, this is my main call):

Bitmap bitmap =
loadBitmap(resources.getDrawable(R.drawable.map_image),
Config.RGB_565);
Bitmap bitmap1 =
loadBitmap(resources.getDrawable(R.drawable.map_image),
Config.RGB_565);
Bitmap bitmap2 =
loadBitmap(resources.getDrawable(R.drawable.map_image),
Config.RGB_565);
[...]
Bitmap bitmap9 =
loadBitmap(resources.getDrawable(R.drawable.map_image),
Config.RGB_565);

about 10 times

The map_image has the following dimensions: 1565x480
So it's using up 1502.4kb of memory: 1565*480*2/1000   (*2 => RGB_565)

The loadBitmap function used in the above few lines will call the
following function:

static public Bitmap loadBitmap(Drawable drawable, Config
bitmapConfig) {
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
long sizeStart;
long size;

Bitmap bitmap;

sizeStart = Debug.getNativeHeapAllocatedSize();
bitmap = Bitmap.createBitmap(width, height, bitmapConfig);
size = Debug.getNativeHeapAllocatedSize() - sizeStart;
System.out.println("Created : " + bitmapConfig.toString() + " : 
" +
size/1000 + " Kb, " + bitmap.getWidth() + "x" + bitmap.getHeight());

Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
return bitmap;
}


Now when I run the code, I will get about 5 calls to the loadBitmap:
Created : RGB_565 : 1503 Kb, 1565x480
Created : RGB_565 : 1503 Kb, 1565x480
Created : RGB_565 : 1503 Kb, 1565x480
Created : RGB_565 : 1503 Kb, 1565x480
Created : RGB_565 : 1503 Kb, 1565x480
Before getting the dreaded:
1502400-byte external allocation too large for this process.
Out of memory: Heap Size=5123KB, Allocated=2481KB, Bitmap Size=11183KB
VM won't let us allocate 1502400 bytes

Now I understand that 1502400 bytes is the memory needed to load a new
bitmap.
I'm guessing that the 5123+2481KB represent (approximately) the 5
previously loaded bitmaps (7604/5=1520.8)

But what in god's name is that Bitmap Size value? what is using up
those 11 megs?

My subsequent question is: In theory I should be able to load 10 times
that 1.5 mb bitmap in my memory (before I reach the 16mb limit) why am
getting an exception after the fifth bitmap?

Thank you very much for any reply or leads you might be able to give
me,

Regards,

-- 
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


[android-developers] Re: Intents problem

2010-05-08 Thread blew
You may want to update your intent with the latest app state just
before the user leaves your application.
That way your onResume will work with the most up-to-date intent:
Either the one from updated by your widget or the one updated by your
app itself.


On May 8, 12:25 am, Esdras Beleza  wrote:
> Hi,
>
> I have a widget that talks with an activity from my application. When
> I click in a button on my widget, it sends an intent to my application
> main activity, that handles it and shows a dialog.
>
> My problem is that if I go to another application, alternate between
> applications, go to home screen and back -- if my application is not
> in foreground -- and I go back to her, the old intent that my widget
> sent to my activity is handled again and suddenly a dialog is shown.
>
> The intent is handled using onResume, to handle the cases where the
> application was just created and when the application is restarted by
> widget, but also happens when user comes back to it.
>
> Does anybody here have any tip that could help me to solve this
> problem?
>
> Thanks in advance,
>
> Esdras Beleza
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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


[android-developers] Re: save (complex?) application state to bundle

2010-05-06 Thread blew
OK, I think I got the main idea.
Many thanks for pointing me in the right direction!

On May 5, 5:11 pm, TreKing  wrote:
> On Wed, May 5, 2010 at 10:06 AM, blew  wrote:
> > OK, that leaves me with figuring out how to serialize parts of objects.
>
> If you use the Parcelable methodology, you can just put and retrieve the
> bits you care about to and from a Parcel.
>
> -
> TreKing - Chicago transit tracking app for Android-powered 
> deviceshttp://sites.google.com/site/rezmobileapps/treking
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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


[android-developers] Re: How to draw smooth gradients?

2010-05-06 Thread blew
In that case maybe we're looking at this the wrong way.
Perhaps you need to apply a filter to your canvas to get you the
required result?

PaintFlagsDrawFilter setfil = new PaintFlagsDrawFilter(0,
Paint.FILTER_BITMAP_FLAG);
Canvas _canvas = new Canvas();
_canvas.setBitmap(someBitmap);
_canvas.setDrawFilter(setfil);

Also, applying a filter will let you know whether your canvas is
taking the extra "properties" into consideration correctly (much
easier to see with some obvious filter).
If your code is working properly you'll see the new filter and we'll
know that you're actually drawing in 888, from there on we'll have to
look for something else to make your gradients smoother.
If your code isn't working properly you won't see the new filter and
we'll know that there's something wrong with your code.

On May 6, 3:23 pm, fexpop  wrote:
> On 6 Mai, 14:23, blew  wrote:
>
> > Why don't you put your bitmap888 when constructing your canvas888.
>
> > Canvas canvas888 = new Canvas(bitmap888);
>
> Ooops, that's because I wanted to edit the actual code I used for this
> message. I added the 888 for clarity, but forgot so in the
> constructor. In other words: A mistake in transcription ;-)
>
> Nevertheless, in my actual code I'm really drawing on the canvas888
> with bitmap888 behind it. The result is as stated above: Looks like
> 5-6-5.
>
> Kind regards and thanks,
>
> Felix
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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


[android-developers] Re: How to draw smooth gradients?

2010-05-06 Thread blew
Can't really test your code now, but:
Why don't you put your bitmap888 when constructing your canvas888.

Canvas canvas888 = new Canvas(bitmap888);



On May 6, 11:32 am, fexpop  wrote:
> On 5 Mai, 16:44, blew  wrote:
>
> > I think you can do this by drawing the gradients in a 8-8-8 bit color
> > defined canvas
> > this should apply the configuration to all elements in the canvas:
> > Bitmap bitmap = Bitmap.createBitmap(width, height,
> > Bitmap.Config.ARGB_);
> > Canvas canvas = new Canvas(bitmap);
>
> Hmm, how do I actually put the canvas contents on the screen then?
>
> The only way I know of is drawing it on a view's canvas in the
> onDraw() method:
>
> @override
> protected void onDraw(Canvas canvas) {
>    Bitmap bitmap888 = Bitmap.createBitmap(canvas.getWidth(),
> canvas.getHeight(),
>    Bitmap.Config.ARGB_);
>    Canvas canvas888 = new Canvas(bitmap);
>    drawSomething(canvas888); // actually draw gradient on canvas888
>
>    canvas.drawBitmap(bitmap888, 0, 0, null);
>
> }
>
> When I do it that way, the gradient is rendered as 5-6-5 again.
>
> Any ideas?
>
> Kind regards,
>
> Felix
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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


[android-developers] Re: save (complex?) application state to bundle

2010-05-05 Thread blew
OK, that leaves me with figuring out how to serialize parts of
objects.
Thanks alot.

On May 3, 9:47 pm, TreKing  wrote:
> On Fri, Apr 30, 2010 at 11:33 AM, blew  wrote:
> > Unfortunately it appears that we can't serialize bitmaps and considering
> > they're a part of my "creature" I can't seem to see a workaround.
>
> You don't have to serialize out every single part of an object - only those
> parts which contain it's current state. In this case you would care about
> which image was currently displayed, so you'd save an index or ID for that
> image. The images themselves don't need to be serialized out since they
> don't change. Just reload them as necessary.
>
> ---­--
> TreKing - Chicago transit tracking app for Android-powered 
> deviceshttp://sites.google.com/site/rezmobileapps/treking
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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


[android-developers] Re: How to draw smooth gradients?

2010-05-05 Thread blew
> So how do I tell the device to use 8-8-8 bit color depth for
> displaying the color bar?

I think you can do this by drawing the gradients in a 8-8-8 bit color
defined canvas
this should apply the configuration to all elements in the canvas:
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_);
Canvas canvas = new Canvas(bitmap);

-- 
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


[android-developers] save (complex?) application state to bundle

2010-05-03 Thread blew
Hello Android Developers!

This is a bit complicated to explain (and my first post), so bear with
me please:
I am currently trying to figure out the best way of saving my
application's state in a bundle on the onSaveInstanceState event
(working on a game). My application's state is based on a "world"
class which contains various objects.
Among these objects there is a creature object which contains bitmaps
(Bitmap object)(allowing me to draw the various sprites of the
creature when it's walking with more flexibility and accessibility).

Bit of creature constructor
Java:
  //load creature sprites
  for (int i = 1; i<= _spriteCount; i++){
   //walk left
   try{
bitmap = BitmapFactory.decodeResource(resources,
R.drawable.class.getDeclaredField("creature_" i).getInt(null));
   }catch(Exception e){
bitmap = null;
   }
   walkImages.add(bitmap);
  }


After looking around for a few hours I found that serializing the
world object (and all its sub-objects) was an acceptable way of saving
it in the bundle. Unfortunately it appears that we can't serialize
bitmaps and considering they're a part of my "creature" I can't seem
to see a workaround.

So here come my questions:
1- Am I doing something fundamentally wrong? (not supposed to save
bitmaps in objects? supposed to handle bitmaps in a separate class
which I don't pass on the bundle and reload my bitmaps when restoring
the application? ...)
2- Is there another way of passing my "world" object into my bundle
(would using Parcelable work?)

I'm not sure what my options are at this point. I hope I was clear
enough; don't hesitate to ask for any (probably needed)
clarifications.

In any case, thanks for reading, any help would be much appreciated.

-- 
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