根据图片的大小改变图片的分辨率

时间:2012-05-08 10:00:39

标签: android image bitmap resolution

我正在编写一个使用手机相机拍照的应用,然后再显示它。问题是,对于具有高分辨率相机的手机,这会导致应用程序崩溃,因此我使用isSampleSize降低了分辨率,这解决了这个问题。但是现在我的手机具有较低分辨率的摄像头存在问题 - 图像质量很差。有没有办法检查图像内存消耗是什么,并根据这决定我是否要降低质量?

1 个答案:

答案 0 :(得分:0)

要重新缩放我的照片,因为我的图像高度有限制,我使用下面的代码来调整它的大小。但我不想调整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);
            }