标签:bit-manipulation image-processing android
我必须将从相机/画廊捕获的图像上传到服务器.在许多应用程序中,我看到分辨率为1000X560的图像大小为35 KB.以我为例,图像大小最大为380 KB.我的手机的相机拍摄的分辨率为2368X4224的图像尺寸小于< 2 MB.如何在保持较小尺寸的情况下获得高分辨率图像?到目前为止,这是我尝试过的:
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(realPath, bmOptions);
bmOptions.inSampleSize = 1;
bmOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
bmOptions.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(realPath, bmOptions);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
我已经读过documentation.我面临的问题是如何确定图像的最小宽度和最小高度.
解决方法:
嘿你能检查http://voidcanvas.com/whatsapp-like-image-compression-in-android/ 这个链接
我认为这是最好的图像压缩教程.
还要检查此答案:https://stackoverflow.com/a/26928768/5275436
希望对您有所帮助.
编辑:这是图像调整大小.
// max Height and width values of the compressed image is taken as 816x612
float maxHeight = 816.0f;
float maxWidth = 612.0f;
float imgRatio = actualWidth / actualHeight;
float maxRatio = maxWidth / maxHeight;
// width and height values are set maintaining the aspect ratio of the image
if (actualHeight > maxHeight || actualWidth > maxWidth) {
if (imgRatio < maxRatio) { imgRatio = maxHeight / actualHeight; actualWidth = (int) (imgRatio * actualWidth); actualHeight = (int) maxHeight; } else if (imgRatio > maxRatio) {
imgRatio = maxWidth / actualWidth;
actualHeight = (int) (imgRatio * actualHeight);
actualWidth = (int) maxWidth;
} else {
actualHeight = (int) maxHeight;
actualWidth = (int) maxWidth;
}
}
标签:bit-manipulation,image-processing,android 来源: https://codeday.me/bug/20191118/2028747.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。