位图比例破坏质量 [英] Bitmap scale destroy quality

查看:101
本文介绍了位图比例破坏质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Android Wear制作了表盘.
但是问题是图像缩放.调整大小时,背景,标记和小工具的图像质量降低.

I have made a Watch Face for Android Wear.
But the problem is image scaling. Images for background, markers and gadgets are of reduced quality when I resize them.

例如,我将480x480背景图像放在drawable-nodpi文件夹中(我也尝试过其他dpi),然后像这样重新缩放它:

For example, I put 480x480 background image in drawable-nodpi folder (I have tried other dpi as well), and I rescale it like this:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
Bitmap bgImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.ticks_1, options);
bgImage = Bitmap.createScaledBitmap(bgImage , width, height, false);

以下是图像:

这就是我的手表:

我在调整大小上有问题吗?

Am I doing something wrong with resizing or what?

推荐答案

我找到了一个解决方法

I have found a solution here and it works great.
Here is the part of the code for scaling the image:

public Bitmap getResizedBitmap(Bitmap bitmap, int newWidth, int newHeight) {
        Bitmap resizedBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);

        float scaleX = newWidth / (float) bitmap.getWidth();
        float scaleY = newHeight / (float) bitmap.getHeight();
        float pivotX = 0;
        float pivotY = 0;

        Matrix scaleMatrix = new Matrix();
        scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);

        Canvas canvas = new Canvas(resizedBitmap);
        canvas.setMatrix(scaleMatrix);
        canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG));

        return resizedBitmap;
    }

这篇关于位图比例破坏质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆