Android的位图setPixel正确好好尝试一下工作? (设定值,然后读取不同的值) [英] Android Bitmap setPixel doens't work correctly? (set value, then read a different value)

查看:397
本文介绍了Android的位图setPixel正确好好尝试一下工作? (设定值,然后读取不同的值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用与setPixel()的像素设定为一定值,但后来当我打电话getPixel后用同样的像素对,它返回一个不同的值。

I use setPixel() to set the pixel to a certain value, but then when I call getPixel on the same pixel right after it, it returns a different value.

它正常工作时的α= = 255,但是任何其它的值,它提供了不同的值;

It works fine when alpha==255, but any other value it gives a different value;

这是对华硕变压器测试,蜂窝3.2

This was tested on an Asus Transformer, Honeycomb 3.2

int newPixel=Color.argb(alpha, red, green, blue);
if(x==74&&y==86){
    Log.w("PuzzleMaker","newPixel:"+newPixel+","+image.getConfig().name()+","+image.isMutable());
}
image.setPixel(x,y,newPixel);
if(x==74&&y==86){
    int testPixel=image.getPixel(x, y);
    Log.w("PuzzleMaker","testPixel:"+testPixel);
}

日志:

newPixel: 13426418,ARGB_8888,true
testPixel: -16777216

的2号在日志中应该是相同的。

The 2 numbers in the log should be the same.

推荐答案

原来,有一个非常简单的解决方案。我想通了,对setPixel()方法是由阿尔法乘以红色,绿色和蓝色的值,则仅设置R,G,B。

It turned out to have a very simple solution. I figured out that the setPixel() method was multiplying the red,green, and blue values by the alpha, then only setting r,g,b.

只需简单地调用image.setHasAlpha(真)修复了这个所以它会将所有4个值。

Just simply calling image.setHasAlpha(true) fixes this so it sets all 4 values.

这篇关于Android的位图setPixel正确好好尝试一下工作? (设定值,然后读取不同的值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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