Android缩放图片Bitmap、Drawable

Android缩放bitmap是开发应用时常常使用的,对于Drawable可以先转换为bitmap再进行缩放<pre name="code" class="java"><pre name="code" class="java">	/**
	 * Drable转为Bitmap
	 * @author YOLANDA
	 * @param d
	 * @return
	 */
	public static Bitmap getDrawable2Bitmap(Drawable d){
		BitmapDrawable bd = (BitmapDrawable) d;
		Bitmap bm = bd.getBitmap();
		return bm;
	}

 
 
 
 
 
 
/**
	 * 缩放图片
	 * @author YOLANDA
	 * @Time 2014年8月27日 上午11:32:21
	 * @param paramBitmap 原图
	 * @param newWidth 新的宽度
	 * @param newHeight 新的高度
	 * @return
	 */
	public static Bitmap getScaleBitmap2Bitmap(Bitmap paramBitmap, int newWidth, int newHeight) {
		int i = paramBitmap.getWidth();
		int j = paramBitmap.getHeight();
		float f1 = ((float)newWidth) / i;
		float f2 = ((float)newHeight) / j;
		if (f1 <= 0.0F) {
			f1 = 1.0F;
		}
		if (f2 <= 0.0F) {
			f2 = 1.0F;
		}
		Matrix localMatrix = new Matrix();
		localMatrix.postScale(f1, f2);
		return Bitmap.createBitmap(paramBitmap, 0, 0, i, j, localMatrix, true);
	}

你可能感兴趣的:(Android缩放图片,Android缩放Bitmap,缩放Drawable)