在没有Android的自动缩放加载图像 [英] Load image without autoscaling in Android

查看:143
本文介绍了在没有Android的自动缩放加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个地图通过图像,其中每个黑色像素相当于一个墙上的游戏,黄色的鲜花(1)和草绿色(0)
到目前为止,我有这个图像(50×50):
http://i.imgur.com/Ydj9Cp2.png

I'm trying to create a map for a game through an image, where each black pixel is equivalent to a wall, and yellow to flowers(1) and green grass(0) so far i had this image (50x50): http://i.imgur.com/Ydj9Cp2.png

这里的问题似乎是,当我读了我的code中的形象,得到它的扩大到100×100,甚至强硬的我有它的原始文件夹中。我不能让它扩张或收缩,因为这会把噪声和图像模糊,然后地图将无法读取。

the problem here seems to be that, when i read the image on my code, it get's scaled up to 100x100, even tough i have it on the raw folder. I can't let it scale up or down because that will put noise and blur on the image and then the map won't be readable.

在这里,我有我的code:

here i have my code:

(...)
Bitmap tab=BitmapFactory.decodeResource(resources, com.example.lolitos2.R.raw.mappixel);
    //tab=Bitmap.createScaledBitmap(tab, 50, 50, false);
    Log.e("w", tab.getWidth()+"."+tab.getHeight());
    for (int i = 0; i < tab.getWidth(); i++) {
        for (int j = 0; j < tab.getHeight(); j++) {
            int x = j;
            int y = i;
            switch (tab.getPixel(x, y)) {
            // se o é uma parede
            case Color.BLACK:
                getParedes()[x][y] = new Parede(x, y);
                break;
            case Color.GREEN:
                fundo.add(new Passivo(x,y,0));
                break;
            default:
                fundo.add(new Passivo(x,y,1));
            }

        }
    }

我怎么能读我的图像地图不缩放呢?

How can i read my image Map without rescaling it?

推荐答案

,把它们放进绘制-nodpi 文件夹,而不是在原材料,然后只是读取它们的任何其他 BitmapDrawable

Put them in the drawable-nodpi folder, instead of in raw, then just read them as any other BitmapDrawable.

如果你有一些绘制资源系统应永攀
  (也许是因为你执行一些调整图像在自己
  运行时),你应该把它们与nodpi目录
  配置预选赛。与此预选赛资源被认为是
  密度无关,系统将不会对它们。

If you have some drawable resources that the system should never scale (perhaps because you perform some adjustments to the image yourself at runtime), you should place them in a directory with the nodpi configuration qualifier. Resources with this qualifier are considered density-agnostic and the system will not scale them.

(从 http://developer.android.com/guide/practices/screens_support。 HTML

(如果需要的话,还有其他的方法,例如,你可以提供一个强度气体参数 BitmapFactory.de codeResource <选项/ code>)。

(If necessary, there are other ways, e.g. you can provide an inDensity parameter to the options of BitmapFactory.decodeResource).

这篇关于在没有Android的自动缩放加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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