DrawableUtil.java 760 B

1234567891011121314151617181920
  1. package com.edufound.mobile.util;
  2. import android.app.Activity;
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.graphics.drawable.BitmapDrawable;
  6. public class DrawableUtil {
  7. public static BitmapDrawable getNewDrawable(Activity context, int restId, int dstWidth, int dstHeight) {
  8. Bitmap Bmp = BitmapFactory.decodeResource(
  9. context.getResources(), restId);
  10. Bitmap bmp = Bmp.createScaledBitmap(Bmp, dstWidth, dstHeight, true);
  11. BitmapDrawable d = new BitmapDrawable(bmp);
  12. Bitmap bitmap = d.getBitmap();
  13. if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
  14. d.setTargetDensity(context.getResources().getDisplayMetrics());
  15. }
  16. return d;
  17. }
  18. }