Search code examples
cocos2d-android

Got error on Large Image Size (1600*2560) png format?


I got an error on Large Image size is about 1600*2560. LogCat Detail is below :

E/AndroidRuntime(2451): FATAL EXCEPTION: main
E/AndroidRuntime(2451): java.lang.OutOfMemoryError
E/AndroidRuntime(2451): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(2451): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
E/AndroidRuntime(2451): at org.cocos2d.nodes.CCTextureCache$2.load(CCTextureCache.java:210)
E/AndroidRuntime(2451): at org.cocos2d.opengl.CCTexture2D.setLoader(CCTexture2D.java:194)
E/AndroidRuntime(2451): at org.cocos2d.nodes.CCTextureCache.createTextureFromFilePath(CCTextureCache.java:201)
E/AndroidRuntime(2451): at org.cocos2d.nodes.CCTextureCache.addImage(CCTextureCache.java:67)
E/AndroidRuntime(2451): at org.cocos2d.nodes.CCSprite.<init>(CCSprite.java:366)
E/AndroidRuntime(2451): at org.cocos2d.nodes.CCSprite.sprite(CCSprite.java:267)

What is the solution for this ?


Solution

  • When you use BitmapFactory to decode your file, you have to specify the Options, such as image width, height, color format, sample size. Then you will not run out of your memory.