1

我在加载资产图像时无法放大它。对 BitmapDrawable(Resources, BitmapDrawable) 的新调用在 1.6 SDK 上不可用。是否有一种解决方法可以以旧方式加载 BitmapDrawable,然后以某种方式对其进行操作?我试过调用 setTargetDensity() 无济于事。我的代码(不能正确扩展)是:

    ImageView iv = (ImageView)view.findViewById(R.id.image);
 iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(path)));
4

1 回答 1

5

在做了一些好的旧 RTFM 之后,我找到了一种有效的方法。以下代码有效:

  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);

背景见http://d.android.com/guide/practices/screens_support.html

于 2010-03-31T16:58:21.777 回答