Say I have a bitmap referenced in xml, eg
res\drawable\reference.xml:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/original"
/>
The first thing I tried was
BitmapFactory.Options opts= new BitmapFactory.Options();
opts.inJustDecodeBounds=true;
BitmapFactory.decodeResource(res, R.drawable.reference, opts);
The problem is now opts.outWidth
and opts.outHeight == -1
. This is because BitmapFactory
doesn't know how to follow this alias to the original file - in fact it tries do decode the compiled xml
file and fails.
This question has one answer to the problem but does not address the memory concerns:
It uses res.getDrawable(R.drawable.reference)
to get a BitmapDrawable
, and then get the Bitmap
from that. This is not what I want. It is a very large image and I only want its dimensions.