Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片尺寸压缩部分 #1

Open
xinxina opened this issue Dec 13, 2016 · 1 comment
Open

图片尺寸压缩部分 #1

xinxina opened this issue Dec 13, 2016 · 1 comment

Comments

@xinxina
Copy link

xinxina commented Dec 13, 2016

options.inSampleSize = computSampleSize(options, actualOutWidth, actualOutHeight);
options.inJustDecodeBounds = false;
Bitmap scaledBitmap = null;
try {
scaledBitmap = BitmapFactory.decodeFile(srcImagePath, options);
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
if (scaledBitmap == null) {
return null;//压缩失败
}
//生成最终输出的bitmap
Bitmap actualOutBitmap = Bitmap.createScaledBitmap(scaledBitmap, (int) actualOutWidth, (int) actualOutHeight, true);

这部分的代码。第一行,是获得压缩比例。而在看了computSampleSize 方法之后发现,我觉得这个方法可以不添加吧。首先,拿到的是四舍五入的int比例,不准确的。而且应该获得宽 高 这两个比例之间最大的那一个。这样才能保证是压缩。 此外,继续下面的代码,获得压缩比例之后根据这个比例压缩了图片获得scaledBitmap ,之后又根据 需要的宽高尺寸 获得 actualOutBitmap 。

@ButaiKirin
Copy link

你的api接口在哪里?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants