[android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Hi Joao, Here it is: BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inScaled = false; Bitmap b = BitmapFactory.decodeResource( context.getResources(), R.drawable.testImage, opts ); b.getWidth(); // NPE This always works for me when I test it. Thanks, Chad On Sep 29, 1:15 pm, Joao Braga jp.am.br...@gmail.com wrote: Paste your code here...just the line where you try to create the 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Try this: Bitmap bitmap; bitmap = BitmapFactory.decodeResource(res, R.drawable.image); bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), false); //if you want to make it scaleble -- 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: BitmapFactory.decodeResource returning null sometimes for local resource
I got a null pointer when my PNG file was incorrectly saved. Since I was developing on Linux, I loaded it into GIMP and saved it back out and it loaded. So you might check using one of the image files supplied in the SDK. -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
ops, I forgot the resources: Bitmap bitmap; bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image); bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), false); //if you want to make it scaleble Note: If you are creating this bitmap from the class of your main activity, you can get the resources only by calling the getResources() (without context). I think you may be getting this problem cause of the context.getResources(). If you need to create the bitmap outside the class of your main activity you set a parameter for the method (or the constructor) of the class will create the bitmap like this: public Bitmap CreateBitmapFactory (Resources res, int bitmapResourceId ) { return BitmapFactory.decodeResource(res, bitmapResourceId ); } You should call it from your main Activity class for example: Bitmap bmp = object.CreateBitmapFactory( gerResources(), R.drawable.image); -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Thanks for the response Joao, Interesting. Do you think there's a bug in the decodeResource() when using BitmapFactory.Options? -Chad On Thu, Sep 29, 2011 at 1:49 PM, Joao Braga jp.am.br...@gmail.com wrote: Try this: Bitmap bitmap; bitmap = BitmapFactory.decodeResource(res, R.drawable.image); bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), false); //if you want to make it scaleble -- 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 -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Can you get to your resource through R.drawable.image name ? You can get errors if you store pictures with invalid names for the resources (spaces, special chars, numbers etc). -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Maybe, but I can't tell since I never used it. Did the code work for you? -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Thanks for the responses guys, Just a note: My code always works when I test it. The bug is happening once every 200k sessions (as reported via Android Market). -Chad On Thu, Sep 29, 2011 at 1:58 PM, Chad Ata chad...@gmail.com wrote: Thanks for the response Joao, Interesting. Do you think there's a bug in the decodeResource() when using BitmapFactory.Options? -Chad On Thu, Sep 29, 2011 at 1:49 PM, Joao Braga jp.am.br...@gmail.com wrote: Try this: Bitmap bitmap; bitmap = BitmapFactory.decodeResource(res, R.drawable.image); bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), false); //if you want to make it scaleble -- 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 -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
It's an architectural problem. What's your application about? What does it do? -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Hi Joao, Yes that code works for me - actually I was already doing something similar in a different part of my code. Unfortunately, since it's such a rare bug I won't know if it really fixed the problem until I deploy it to my users. -Chad On Thu, Sep 29, 2011 at 2:01 PM, Joao Braga jp.am.br...@gmail.com wrote: Maybe, but I can't tell since I never used it. Did the code work for you? -- 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 -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
It's a game. At a certain part it loads a large transparent png - about 900x300 or something like that. This issue seems to happen only with the larger images, which is why I was thinking it had to do with possible low memory situation. -Chad On Thu, Sep 29, 2011 at 2:05 PM, Joao Braga jp.am.br...@gmail.com wrote: It's an architectural problem. What's your application about? What does it do? -- 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 -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
I see, but it souldn't be a problem since the phones have enough memory to load a image like that. I'm just talking about the image, I don't know how the rest of your engine is managing the memory. But you said something about 200k sessions...how this sessions work? The clients connect to a server (computer) or the clients (phones) can host games and the crash happens when it is hosting a certain number of clients? Tell us about your architecture -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
On some phones, like the small screen Motorola's, we've found that we really push the memory limitations. If a user has a lot of junk of the screen (in-game), then they risk OOM exception. We are aggressively calling bitmap.recycle() whenever an image is no longer being used - and that has been really helpful. But every once in a while, we still notice these weird bugs. As for the sessions, I just mean the time between onResume() and onPause(). So if 200k users play the game once, 1 of them gets the error - which is being reported via Android Market. On Thu, Sep 29, 2011 at 2:16 PM, Joao Braga jp.am.br...@gmail.com wrote: I see, but it souldn't be a problem since the phones have enough memory to load a image like that. I'm just talking about the image, I don't know how the rest of your engine is managing the memory. But you said something about 200k sessions...how this sessions work? The clients connect to a server (computer) or the clients (phones) can host games and the crash happens when it is hosting a certain number of clients? Tell us about your architecture -- 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 -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
I see... Well I don't know the style of your game and how it was developed. I'm developing a game engine myself and for the memory issue, we are building a Memory Manager that knows exactly when to allocate, when to free and when to reuse an object of the game. The result of it is less load time and less memory being used. On the other hand it takes more time to create the game itself. I don't know if it fits to your problem, but seems to me that it's a option to be considered. -- 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
Re: [android-developers] Re: BitmapFactory.decodeResource returning null sometimes for local resource
Hi Joao, Cool, that's similar to what we've done. I think I'm going to ignore this problem until I get a few more bug reports - hopefully with more details. Thanks for helping out! -Chad On Thu, Sep 29, 2011 at 2:44 PM, Joao Braga jp.am.br...@gmail.com wrote: I see... Well I don't know the style of your game and how it was developed. I'm developing a game engine myself and for the memory issue, we are building a Memory Manager that knows exactly when to allocate, when to free and when to reuse an object of the game. The result of it is less load time and less memory being used. On the other hand it takes more time to create the game itself. I don't know if it fits to your problem, but seems to me that it's a option to be considered. -- 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 -- 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