views:

138

answers:

1

I'm having trouble getting an asset image to scale up when I load it. The new call to BitmapDrawable(Resources, BitmapDrawable) is not available on 1.6 SDK. Is there a workaround to load the BitmapDrawable the old way and then somehow manipulate it? I have tried calling setTargetDensity() to no avail. My code (which doesn't scale properly) is:

    ImageView iv = (ImageView)view.findViewById(R.id.image);
 iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(path)));
+1  A: 

I found a way that worked, after doing some good old RTFM. The following code works:

  ImageView iv = (ImageView)view.findViewById(R.id.image);
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inScaled = true;
    opts.inDensity = DisplayMetrics.DENSITY_MEDIUM;
    Rect padding = new Rect();
    opts.inTargetDensity = view.getResources().getDisplayMetrics().densityDpi;
    Bitmap bm = BitmapFactory.decodeStream(view.getContext().getAssets().open(path), padding, opts);
    iv.setImageBitmap(bm);

For background see http://d.android.com/guide/practices/screens_support.html

Mark Wigzell