繁体   English   中英

Android-更改位图的像素颜色

[英]Android - Change Pixel color of a bitmap

Namastey,

我想将那些黑色像素更改为位图中的透明像素。 我的位图如下图所示。

我试图通过下面的代码更改那些黑色像素。 但这对我不起作用。

    int [] allpixels = new int [maskImage.getHeight()*maskImage.getWidth()];
    maskImage.getPixels(allpixels, 0, maskImage.getWidth(), 0, 0, maskImage.getWidth(), maskImage.getHeight());
    for(int i = 0; i < allpixels.length; i++){
        if(allpixels[i] == Color.BLACK){
            allpixels[i] = Color.TRANSPARENT;
        }
    }
    maskImage.setPixels(allpixels, 0, maskImage.getWidth(), 0, 0, maskImage.getWidth(), maskImage.getHeight());

有可能这样做吗? 如果是,我该怎么办?

在此处输入图片说明

使用此代码,将像魅力一样工作:

int [] allpixels =新的int [myBitmap.getHeight()* myBitmap.getWidth()]; myBitmap.getPixels(allpixels,0,myBitmap.getWidth(),0,0,myBitmap.getWidth(),myBitmap.getHeight());

for(int i = 0; i <allpixels.lenght; i ++)

{ 
if(allpixels[i] == Color.BLACK)
{ 
    allpixels[i] = Color.RED;
} 

}

myBitmap.setPixels(allpixels,0,myBitmap.getWidth(),0,0,myBitmap.getWidth(),
myBitmap.getHeight());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM