压缩图像和调整图像大小有什么区别?安卓 [英] what is the difference between compressing image and resizing image ? android

查看:320
本文介绍了压缩图像和调整图像大小有什么区别?安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

in my android app , i want to upload image to the server. the problem that the server will not accept images with size larger than 2M. but the user can choose an image larger than 2M.

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

so I want to build a code that will make the image smaller than 2M.

我有拖曳的方法:


  1. 拖曳调整图片大小。如下:

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



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. 也可以压缩图片

  1. also i can compress the image

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

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

这两种方法之间的区别是什么?

what the difference between this tow approaches ?

推荐答案

图片缩放意味着您将缩短图片的分辨率。假设用户选择1000 * 1000像素的图像。你将把图像转换成300 * 300的图像。因此图像尺寸将减小。

Image re sizing means you're going to shorten the resolution of the image. suppose user selects a 1000*1000 px image. you're going to convert the image into a 300*300 image. thus image size will be reduced.

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

And Image compression is lowering the file size of the image without compromising the resolution. Of course lowering file size will affect the quality of the image. There are many compression algorithm available which can reduce the file size without much affecting the image quality.

这篇关于压缩图像和调整图像大小有什么区别?安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆