如何像Facebook和WhatApp做优化图像? [英] how to optimize image like Facebook and WhatApp does?
问题描述
我想优化像WhatsApp的和Facebook的图片文件的大小都在做。我有送5MB图片上的WhatsApp,而接收到的图像具有80KB的大小。接收到的图像看起来与原有的但分辨率小于原来的
I want to optimize the Image file size like whatsapp and facebook are doing. I have send 5MB Image on whatsapp, And received image has size of 80KB. Received image looks identical to the original ones but resolution is less than the original one.
我几乎尝试了所有的源$ C $ CS的机器人形象融为一体$ P $适用于计算器pssion但是,这并不为我工作。然后,我遇到了此链接优化形象,这是做好工作,但仍没有得到结果类似WhatsApp的。
I tried almost all the source codes of android image compression available on stackoverflow but that doesn't work for me. And then i came across this link to optimize the image, which is doing good work but still not getting the result like whatsapp.
我怎样才能实现最大图像融为一体pression不降低图像的质量,同样喜欢WhatsApp的那样?
How can i achieve maximum image compression without degrading the quality of image, Same like whatsapp did?
答与源$ C $ C将是非常有益的。
Answer with a source code will be very helpful.
在此先感谢。
推荐答案
您需要取消code图像(位图)
You need to decode Image (bitmap)
下面是code。
public Bitmap decodeFile(String path) {
// Decode image size
int orientation;
try {
if (path == null) {
return null ;
}
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
// Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 70;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 0;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bm = BitmapFactory.decodeFile(path, o2);
Bitmap bitmap = bm;
ExifInterface exif = new ExifInterface(path);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.e("orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), null, true);
ImageViewChooseImage.setImageBitmap(bitmap);
bitmapfinal = bitmap;
return bitmap ;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
这篇关于如何像Facebook和WhatApp做优化图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!