---
title: "Android 一些工具类／方法收藏"
author: "rafale35"
date: "2010-12-15T17:15:44Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2010-12-15T17:16:04Z"
id: 843122
url: "https://rafale35.iteye.com/blog/843122"
---

```
public Bitmap formatBitMapSize(Bitmap bitmapOrg, int twidth, int theight) {
		// 获取这个图片的宽和高
		int width = bitmapOrg.getWidth();
		int height = bitmapOrg.getHeight();
		// 定义预转换成的图片的宽度和高度
		int newWidth = twidth;
		int newHeight = theight;
		// 计算缩放率，新尺寸除原始尺寸
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;
		// 创建操作图片用的matrix对象
		Matrix matrix = new Matrix();
		// 缩放图片动作
		matrix.postScale(scaleWidth, scaleHeight);
		// 旋转45度
		// matrix.postRotate(45);
		// 生成新的bitmap
		Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
				height, matrix, true);
		return resizedBitmap;
	}
```

 

 ……代加