Android常用图片压缩方式
- 质量压缩
- 尺寸压缩
1. 质量压缩
质量压缩通过相应算法进行优化Bitmap的位深及透明度,来达到压缩图片文件大小的目的,属于有损压缩,但质量压缩不会改变图片的长,宽,像素等信息,也就是说通过质量压缩后的图片,再转还为bitmap的话,所占内存大小是不会变的,仍然会和压缩前一样。这比较适合本地保存,上传服务器等需求,比如微信分享要求缩略图不能超过32KB。
* @param format The format of the compressed image
* @param quality Hint to the compressor, 0-100. 0 meaning compress for
* small size, 100 meaning compress for max quality. Some
* formats, like PNG which is lossless, will ignore the
* quality setting
* @param stream The outputstream to write the compressed data.
* @return true if successfully compressed to the specified stream.
*/
bitmap.compress(CompressFormat format, int quality, OutputStream stream)