---
title: "android对大图片压缩的方法"
author: "Darar"
date: "2011-09-30T13:39:33Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2011-09-30T13:39:33Z"
id: 1183895
url: "https://darar.iteye.com/blog/1183895"
---

像新浪微博一样，把本地的照片进行压缩然后发。
andriod提供了一些方法如下：
压缩图片质量:   
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, fos);   
其中的quality为0~100, 可以压缩图片质量, 不过对于大图必须对图片resize   

这个是等比例缩放:
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);

这个是截取图片某部分:
bitmap = Bitmap.createBitmap(bitmap, x, y, width, height);

这几个方法都是针对Bitmap的, 不过鉴于Bitmap可以从file中读取, 也可以写入file.   

这是我知道Android自带库里中唯一可以缩放和压缩的图片方法.