android - 压缩图像和调整图像大小有什么区别?安卓

标签 android image compression

在我的 android 应用程序中,我想将图像上传到服务器。服务器不接受大于2M的图片的问题。但用户可以选择大于 2M 的图片。

所以我想构建一个代码,使图像小于 2M。

我有两种方法:

  1. 调整图像尺寸。如下:

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);

  1. 我还可以压缩图片

    image.compress(Bitmap.CompressFormat.PNG, 10, fos);

这种牵引方法有什么区别?

最佳答案

图像调整大小意味着您将缩短图像的分辨率。假设用户选择 1000*1000 像素的图像。您要将图像转换为 300*300 图像。因此图像尺寸将减小。

图像压缩是在不影响分辨率的情况下减小图像的文件大小。当然,降低文件大小会影响图像质量。有许多可用的压缩算法可以在不影响图像质量的情况下减小文件大小。

关于android - 压缩图像和调整图像大小有什么区别?安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31156501/

相关文章:

Java/Android : I don't understand why this is slower than expected

javascript - 访问一个 div 的所有图像并显示未定义或没有 src 的图像数

c++ - 使用自定义源 boost Iostreams zlib_error

java - android 数据绑定(bind) - 找不到类 android.view.data

android - 我可以将 Zxing 用于商业目的吗?

android - 如何在 Jetpack Compose 中为图标添加阴影/边框/高程

javascript - HTML,Canvas和WebGL之间的质量差异

图像链接上显示的 css 背景颜色

c# - GZip 或 Deflate 用于 HTTP 压缩

julia - 在 Julia 中使用 Arrow.jl 进行数据压缩