[英]change resolution of picture according to its size
我正在编写一个使用手机相机拍照并显示的应用程序。 问题是,对于具有高分辨率相机的手机,这会导致应用程序崩溃,因此我使用isSampleSize降低了分辨率,从而解决了此问题。 但是现在我的手机分辨率较低的相机出现了问题-图片质量太差了。 有什么方法可以检查图像内存消耗量,并据此决定是否要降低质量?
由于我在图像高度方面存在局限性,因此要重新调整图片尺寸,我使用下面的代码调整了图片尺寸。 但是,除非它超出了我的身高要求,否则我不会调整bmp的大小,希望您可以使用它。 (使用信息流获取我的照片)
if (stream != null) {
img = BitmapFactory.decodeStream(stream, null, o);
float imgHeight = (float) img.getHeight();
Display display = ((WindowManager) ctx.getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay();
float displayHeight = (float) (display.getHeight()-50);
if(imgHeight>displayHeight) {
float scaleFactor = displayHeight/imgHeight;
img = Bitmap.createScaledBitmap(img, (int)(img.getWidth()*scaleFactor), (int)(imgHeight*scaleFactor), false);
}
saveBitmap(new File(getSdPath() + location), img);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.