把图片的图标放小得到缩略图

int phSize;
float PIX_SCALE;
PIX_SCALE = this.getResources().getDisplayMetrics().density;
phSize = (PHO_DIP * (int) (PIX_SCALE + 0.5f));

public Drawable scale(File file) {
		BitmapFactory.Options opt = new BitmapFactory.Options();

		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(file.getAbsolutePath(), opt);
		opt.inJustDecodeBounds = false;
		if (opt.outWidth > opt.outHeight) {
			opt.inSampleSize = opt.outWidth / phSize;
			;
		} else {
			opt.inSampleSize = opt.outHeight / phSize;
		}
		Bitmap b = BitmapFactory.decodeFile(file.getAbsolutePath(), opt);
		Drawable d = new BitmapDrawable(ManagerActivity.this.getResources(), b);
		return d;
	}

 

你可能感兴趣的:(android)