机器人:图像质量调整运行时 [英] android: quality of the images resized in runtime

查看:96
本文介绍了机器人:图像质量调整运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示使用drawBitmap()方法的图像。但在此之前我想根据屏幕大小来调整其大小。我与的结果的图像质量的问题。你可以看到屏幕下方的测试code。我该如何调整在运行时图像质量好?

感谢您的解决方案。

原图:

结果在设备上截图:

 进口android.app.Activity;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.graphics.Canvas;
进口android.graphics.Rect;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.LinearLayout;

进口java.io.IOException异常;
进口的java.io.InputStream;

公共类MyActivity延伸活动{

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        的LinearLayout容器=(的LinearLayout)findViewById(R.id.container);
        container.addView(新景(本){
            @覆盖
            保护无效的OnDraw(帆布油画){
                位图unscaledBitmap;
                尝试 {
                    InputStream的时间= getAssets()打开(图像/ gradient.png)。
                    unscaledBitmap = BitmapFactory.de codeStream(中);
                    附寄();
                    canvas.drawBitmap(unscaledBitmap,空,新的Rect(0,0,320,480),空);
                }赶上(IOException异常E){
                    e.printStackTrace();
                }
            }
        });
    }
}
 

解决方案

请参阅<一个href="http://stackoverflow.com/questions/2041207/android-quality-of-the-images-resized-in-runtime/2043315#2043315">Romain's回答下面。

我想删除这个答案,但我不能,因为它被标记为接受。


需要注意的是安卓的 [当这个答案最初写,没有明确要求的32位彩色] 的也只能做16位色彩,所以有可能是时候,你不需要的斑块。

您也可以尝试使用抖动选项告诉机器人自动应用抖动它们虽然并不完美,可以帮助让事情看起来好一点。

I want to show images using drawBitmap() method. But before I want to resize it according screen dimensions. I have a problem with quality of result image. You can see screenshots and test code below. How can I resize images in runtime with a good quality?

Thank you for solutions.

Original image:

Result screenshot on device:

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import java.io.IOException;
import java.io.InputStream;

public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout container = (LinearLayout) findViewById(R.id.container);
        container.addView(new View(this) {
            @Override
            protected void onDraw(Canvas canvas) {
                Bitmap unscaledBitmap;
                try {
                    InputStream in = getAssets().open("images/gradient.png");
                    unscaledBitmap = BitmapFactory.decodeStream(in);
                    in.close();
                    canvas.drawBitmap(unscaledBitmap, null, new Rect(0, 0, 320, 480), null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

解决方案

Please refer to Romain's answer below.

I would like to delete this answer, but I am unable to since it's marked as accepted.


Note that Android [when this answer was originally written, without explicitly requesting 32-bit colour] would only do 16-bit colour, so there may be times when you get unwanted artifacts.

You can also try using the dither options to tell Android to automatically apply dithering which, while not perfect, can help make things look a bit better.

这篇关于机器人:图像质量调整运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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