[英]Compress image without losing any quality android?
I have created an image picker library in which user can select multiple image for uploading to server.were I'm facing a problem ie, i have to compress the selected images without loosing the quality of image much like in popular application Facebook/Whatsapp etc were images maintain with high quality but less size .i have followed the official doc but it's not really satisfying me.if am uploading size less image only i can load it into UI in a fast manner. 我已经创建了一个图像选择器库,用户可以在其中选择多个图像以上传到server.we面临一个问题,即我必须压缩选定的图像而不会像在流行的应用程序Facebook / Whatsapp等中那样降低图像的质量图像是否保持高质量但尺寸较小。我遵循了官方文档,但并不能真正让我满意。如果要上传尺寸较小的图像,则只能将其快速加载到UI中。
Any suggestions/helps are greatly appreciated. 任何建议/帮助将不胜感激。
Here is a great library on GitHub for reducing image size without losing quality. 这是GitHub上的一个很棒的库,用于减少图像大小而不损失质量。
https://github.com/zetbaitsu/Compressor https://github.com/zetbaitsu/Compressor
Try this: 尝试这个:
int width = YourImageView.getWidth();
int height = YourImageView.getHeight();
Bitmap bitmap = Bitmap.createBitmap((int)width, (int)height, Bitmap.Config.ARGB_8888);
float originalWidth = selectedBitmap.getWidth(), originalHeight = selectedBitmap.getHeight();
Canvas canvas = new Canvas(bitmap);
float scale = width/originalWidth;
float xTranslation = 0.0f, yTranslation = (height - originalHeight * scale)/2.0f;
Matrix transformation = new Matrix();
transformation.postTranslate(xTranslation, yTranslation);
transformation.preScale(scale, scale);
Paint paint = new Paint();
paint.setFilterBitmap(true);
canvas.drawBitmap(selectedBitmap, transformation, paint);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.