Android - png resource converted to a ColorDrawable on android < 4.0 -
according documentation here, png resource should converted bitmapdrawable. i'm observing strange behavior wherein png file has only black pixels in resulting in crash because of classcastexception (wrapped in invocationtargetexception) if try following in custom view's constructor :
... tempdrawable = typedarr.getdrawable(r.styleable.customview_src); // source points png file log.i("testpngtoresource", "canonical class name " + tempdrawable.getclass().getcanonicalname()); tempbitmap = ((bitmapdrawable) tempdrawable).getbitmap(); ... i see following logged on android 2.2 , 2.3
09-24 13:21:37.575: i/testpngtoresource(532): canonical class name android.graphics.drawable.colordrawable
why resource not being converted bitmapdrawable?
this optimization performed aapt. able recognize images made of single color , turn them into, well, single color instead of bitmap. more space-efficient, improves loading times, etc.
Comments
Post a Comment