简体   繁体   English

有效地调整位图的大小,而又不损失android的质量

[英]Resize a bitmap eficiently and without losing quality in android

I want to reduce the size of an image on disk without losing quality. 我想减小磁盘上图像的大小而又不损失质量。 I don't want to change the width and height of original image. 我不想更改原始图像的宽度和高度。

I want to do something like https://tinyjpg.com/ 我想做类似https://tinyjpg.com/的事情

It reduces the size of image without changing the width and height of image. 它减小了图像的尺寸,而没有改变图像的宽度和高度。

You need to compress with jpeg, if you want to reduce size without change measurements. 如果要减小大小而不更改尺寸,则需要使用jpeg压缩。 Try this; 尝试这个;

String file = ...
OutputStream s = new FileOutputStream(file);
BitmapFactory.decodeFile(file).compress(CompressFormat.JPEG, 80, s);
s.close();

80 is compression factor which between 0-100 (0 lowest quality, 100 highest quality). 80是介于0到100之间的压缩系数(0最低质量,100最高质量)。 Try to find best for your situation. 尝试找到最适合您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM