android bitmap 图片处理

本文介绍了Android中Bitmap的处理,包括图片压缩、尺寸缩放、切片、灰度变化、制作倒影和圆角图片的实现方法,通过示例代码详细展示了各种操作的步骤。
摘要由CSDN通过智能技术生成

最近要做图片处理,写了一个工具类。

1.图片压缩

2.图片尺寸缩放

3.图片切片

4.图片灰度变化

5.图片倒影

6.图片圆角制作

看一下代码:

/**
 * 
 * @author gxx
 *图片处理类
 *1.图片压缩
 *2.图片尺寸缩放
 *3.图片切片
 *4.图片灰度变化
 *5.图片倒影
 *6.图片圆角
 */
public class BitmapUtil {
	// 根据质量压缩
	public static Bitmap compressBitmap(Bitmap bitmap) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		bitmap.compress(CompressFormat.JPEG, 100, bos);// 将图片压入流 就是将图片转化为字节数组
		int options = 100;
		while (bos.toByteArray().length / 1024 > 100) {
			bos.reset();// 将管道流清空
			options -= 10;
			bitmap.compress(CompressFormat.JPEG, options, bos);// 重新压入
		}
		bitmap = BitmapFactory.decodeByteArray(bos.toByteArray(), 0,
				bos.toByteArray().length);
		return bitmap;
	}

	// 根据尺寸缩放
	public static Bitmap compressBydensity(Bitmap bm, int newwidth,
			int newheight) {
		int xscale = newwidth / bm.getWidth();
		int yscale = newheight / bm.getHeight();
		Matrix matrix = new Matrix();
		matrix.postScale(xscale, yscale);
		Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
				bm.getHeight(), matrix, true);
		return newbm;

	}

	// 彩色变黑白
	public static Bitmap HuiSeJie(Bitmap bitmap) {
		int width = bitmap.getWidth();
		int height = bitmap.getHeight();
		int[] piexs = new int[width * height];// 像素点数组
		Log.i("gxx", (width*height)+"-----");
		bitmap.getPixels(piexs, 0, width, 0, 0, width, height);// 将图片字节转化对应像素点
		// 每一个像素点处理
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				int grey=piexs[width*i+j];
				piexs[width * i + j] = doChangeHuidu(grey);
			}
		}
	    Bitmap newbm=Bitmap.createBitmap
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值