android - Why is BitmapFactory.decodeResource() slower when I put the images in the drawable folder? -
i've noticed while checking decoding times of resource images, bitmapfactory.decoderesource()
function 3-6 times slower, when move resource image drawable
folder.
question:
does know why happens? images scaled if in drawable
folder? possible prevent without storing copy of image in each folder?
details:
i used following code check decoding times of image.
for(int = 0; < 5; i++){ long time = system.currenttimemillis(); bitmapfactory.decoderesource(getresources(),r.drawable.welcome_01); log.i(tag, "time: " + (system.currenttimemillis() - time)); }
bitmap size: 774 x 1280
device: nexus 6 (which uses drawable-xxxhdpi folder if resource available)
test results:
if image in drawable
folder these decoding times:
08-03 09:18:01.072: i/mainactivity(26242): time: 298 08-03 09:18:01.352: i/mainactivity(26242): time: 280 08-03 09:18:01.656: i/mainactivity(26242): time: 304 08-03 09:18:01.929: i/mainactivity(26242): time: 272 08-03 09:18:02.263: i/mainactivity(26242): time: 334
if in drawable-xxxhdpi
folder these results:
08-03 09:19:49.733: i/mainactivity(26456): time: 54 08-03 09:19:49.786: i/mainactivity(26456): time: 53 08-03 09:19:49.841: i/mainactivity(26456): time: 54 08-03 09:19:49.905: i/mainactivity(26456): time: 64 08-03 09:19:49.966: i/mainactivity(26456): time: 61
i found solution problem.
it might else.
solution:
putting image drawable-nodpi
folder prevents image scaled.
additional infos:
in every other folder images scaled in case, in drawable
folder.
i've checked bitmap sizes after decoding resource inside different folders.
original size 774x1280
drawable folder: bitmap: 2709x4480 drawable-ldpi : bitmap: 3612x5973 drawable-mdpi: bitmap: 2709x4480 drawable-hdpi: bitmap: 1806x2987 drawable-xhdpi: bitmap: 1355x2240 drawable-xxhdpi: bitmap: 903x1493 drawable-xxxhdpi: bitmap: 677x1120 drawable-nodpi: bitmap: 774x1280
thanks joey chong found official answer problem. on android developers page can read following lines:
if resources not available in correct density, system loads default resources , scales them or down needed match current screen's density. system assumes default resources (those directory without configuration qualifiers) designed baseline screen density (mdpi), unless loaded density-specific resource directory. pre-scaling is, thus, system when resizing bitmap appropriate size current screen density.
in short - if don't provide density, android handles them mdpi.
Comments
Post a Comment