【问题标题】:change resolution of picture according to its size根据图片大小改变图片分辨率
【发布时间】:2012-05-08 10:00:39
【问题描述】:

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

【问题讨论】:

    标签: android image bitmap resolution


    【解决方案1】:

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

    【讨论】:

    • 我的问题不在于高度,我希望图像始终保持相同大小。如果内存消耗太高,我需要更改分辨率
    • 我觉得我在 stackoverflow 上看到了一些关于它的东西,但我自己没有玩过那个部分。
    猜你喜欢
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多