调整/缩放位图后,图像质量差 [英] Bad image quality after resizing/scaling bitmap

查看:164
本文介绍了调整/缩放位图后,图像质量差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个纸牌游戏,需要我的卡是不同的大小在不同的环境。我存储我的图片为位图,以便它们能够迅速绘制和重新绘制(动画)。

I'm writing a card game and need my cards to be different sizes in different circumstances. I am storing my images as bitmaps so that they can be quickly drawn and redrawn (for animation).

我的问题是,无论我怎样努力,扩大我的图片(无论是通过一个matrix.postScale,一个矩阵。preSCALE,或createScaledBitmap功能),他们总是出来像素化和模糊。我知道,它的缩放这就是导致问题的原因,图像看起来完美的,当没有调整绘制。

My problem is that no matter how I try and scale my images (whether through a matrix.postScale, a matrix.preScale, or a createScaledBitmap function) they always come out pixelated and blurry. I know that its the scaling thats causing the problem because the images look perfect when drawn without resizing.

我已经通过这两个线程描述每一个解决方案的工作:
<一href="http://stackoverflow.com/questions/2041207/android-quality-of-the-images-resized-in-runtime">android调整运行时
图像质量 <一href="http://stackoverflow.com/questions/4231817/quality-problems-when-resizing-an-image-at-runtime">quality调整问题在运行时图像时

I have worked through every solution described in these two threads:
android quality of the images resized in runtime
quality problems when resizing an image at runtime

但仍然没有得到任何地方。

but still haven't gotten anywhere.

我存储我的位图(到一个HashMap)与此code:

I store my bitmaps (into a hashmap) with this code:

cardImages = new HashMap<Byte, Bitmap>();
cardImages.put(GameUtil.hearts_ace, BitmapFactory.decodeResource(r, R.drawable.hearts_ace));

和用这种方法吸引他们(在卡类):

and draw them with this method (in a Card class):

public void drawCard(Canvas c)
{
    //retrieve the cards image (if it doesn't already have one)
    if (image == null)
        image = Bitmap.createScaledBitmap(GameUtil.cardImages.get(ID), 
            (int)(GameUtil.standardCardSize.X*scale), (int)(GameUtil.standardCardSize.Y*scale), false);

        //this code (non-scaled) looks perfect
        //image = GameUtil.cardImages.get(ID);

    matrix.reset();
    matrix.setTranslate(position.X, position.Y);

    //These methods make it look worse
    //matrix.preScale(1.3f, 1.3f);
    //matrix.postScale(1.3f, 1.3f);

    //This code makes absolutely no difference
    Paint drawPaint = new Paint();
    drawPaint.setAntiAlias(false);
    drawPaint.setFilterBitmap(false);
    drawPaint.setDither(true);

    c.drawBitmap(image, matrix, drawPaint);
}

任何有识之士将大大AP preciated。谢谢

Any insight would be greatly appreciated. Thanks

推荐答案

我对小屏幕分辨率blurY的图像,直到从位图资源负载我禁用缩放:

I had blury images on low screen resolutions until I disabled scaling on bitmap load from resources:

Options options = new BitmapFactory.Options();
    options.inScaled = false;
    Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);

这篇关于调整/缩放位图后,图像质量差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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