Android 2.2的扭曲画面的色彩? [英] Android 2.2 distorts picture colors?

查看:143
本文介绍了Android 2.2的扭曲画面的色彩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些.png文件在我的应用程序。我需要在运行时加载这些,并获得一定的像素精确的色彩从他们身上。这一点很重要,我不希望扩大这些图片。我没有在UI上显示它们直接,他们作为地图。

I have some .png files in my app. I need to load these during runtime, and get the exact colors of certain pixels from them. It's important, that I do not want to scale these pictures. I don't show them on the UI directly, they serve as maps.

现在,在Android 1.5,有这个没问题。我在'/ RES /绘制'目录把这些图像,具有BitmapFactory它们加载到一个位图对象,并用它来获得所需像素的颜色。例如。像素(100,50)具有的颜色的RGB(100,1,100)。

Now, on Android 1.5, there's no problem with this. I put these images in the '/res/drawable' dir, load them with BitmapFactory into a Bitmap object, and use it to get the color of the desired pixels. E.g. pixel (100, 50) has the color RGB(100, 1, 100).

在机器人2.2寿,相同的过程的结果变化的颜色(对于相同的像素),所以我得到的RGB(99,3,102)/ RGB(101,2,99)/等为相同的(100, 50)像素。我查了位图对象的分辨率,似乎是没有得到缩放。

On Android 2.2 tho, the same procedure results varying colors (for the same pixel), so I get RGB(99, 3, 102) / RGB(101, 2, 99) / etc. for the same (100, 50) pixel. I checked the resolution of the Bitmap object, it seems that is didn't get scaled.

有人能解释一下,为什么我得到扭曲的颜色值?

Could somebody explain, why I get distorted colour values?

推荐答案

解决:它的出现,是在Android 2.2,我一定要设置正确的位图的配置。不知怎的,低于2.2的版本管理,以做到这一点(或者更少的configs是这些支持,系统猜到了正确的配置,不知道)。

Solved: It appears, that on Android 2.2, I have to set the correct bitmap configuration. Somehow, versions below 2.2 managed to do this (or maybe fewer configs are supported on those, and the system guessed the config correctly, don't know).

不管怎么说,这里的code我现在用的:

Anyways, here's the code I use now:

BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inDither=false;
        opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap mask = BitmapFactory.decodeResource(getResources(), R.drawable.picture, opt);

这篇关于Android 2.2的扭曲画面的色彩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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