0

我使用的逻辑如下,但仍然模糊

public static Bitmap getBitmapFromPath(int targetW, int targetH,
            String photopath, int dstWidth, int dstHeight,
            ScalingLogic scalingLogic) {

        Options options = new Options();
        options.inJustDecodeBounds = true;
        options.inDither=true;
        options.inScaled=true;
        options.inPreferQualityOverSpeed=true;
        options.inPurgeable=true;
        options.inInputShareable=true;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        BitmapFactory.decodeFile(photopath, options);
        options.inJustDecodeBounds = false;
        options.inSampleSize = calculateSampleSize(options.outWidth,
                options.outHeight, dstWidth, dstHeight, scalingLogic);
        Bitmap bitmap = BitmapFactory.decodeFile(photopath, options);

        return bitmap;

    }

public static int calculateSampleSize(int srcWidth, int srcHeight,
            int dstWidth, int dstHeight, ScalingLogic scalingLogic) {
        if (scalingLogic == ScalingLogic.FIT) {
            final float srcAspect = (float) srcWidth / (float) srcHeight;
            final float dstAspect = (float) dstWidth / (float) dstHeight;

            if (srcAspect > dstAspect) {
                return srcWidth / dstWidth;
            } else {
                return srcHeight / dstHeight;
            }
        } else {
            final float srcAspect = (float) srcWidth / (float) srcHeight;
            final float dstAspect = (float) dstWidth / (float) dstHeight;

            if (srcAspect > dstAspect) {
                return srcHeight / dstHeight;
            } else {
                return srcWidth / dstWidth;
            }
        }
    }

任何身体请帮助我

4

1 回答 1

0

您可以使用 Bitmap 的createScaledBitmap创建按比例(缩小)的图像而不会损失质量。

于 2013-06-28T06:03:38.687 回答