我在使用位图图像。 透明部分是用品红色着色的。 在某些语言中,颜色可以设置为透明。 试图处理原始位图图像的洋红色透明像素。
从SD卡加载位图:
bitmap bitmap=bitmap factory.decode file (我的图像路径;
复制到另一个位图中使其可变。
bitmap bitmap2=bitmap.copy (bitmap.config.argb _ 8888,true );
尝试逐像素扫描以找到洋红色像素并更改透明度。
for(intx=0; x
for(inty=0; y
if(bitmap2.getpixel(x,y )==color.RGB )0xff,0x 00,0x ff )
{
int alpha=0x00;
bitmap2.setpixel(x,y,color.argb ) alpha,0xff,0xff,0xff ); //changingthetransparencyofpixel (x,y ) )。
}
}
}
但是,想要变透明的像素会转换为黑色。 通过更改alpha,最终颜色为argb ()中提到的颜色) )但没有提到alpha。 例如color.argb ) )0xff、0xff、0xff、0xff、0xff )、0xff )到白色、color.argb )
我不知道这是怎么回事。
可能没有阿尔法通道,我应该先设置/定义它吗? 好的,怎么样?
编辑1 :
der gol…根据lum的评论,我修改了我的代码:
Paint mPaint=new Paint (;
mpaint.setalpha(0;
MPa int.set xfermode (newporterduffxfermode (porter duff.mode.dst _ out );
mpaint.setantialias(true;
bitmap bitmap=bitmap factory.decode file (mybackimagepath ).copy(bitmap.config.argb_8888,true );
canvas canvas=new canvas (位图);
canvas.drawbitmap(bitmap,0,0,mPaint );
if (bitmap.getpixel (0,0 )==color.RGB )0xff,0x 00,0x ff )
{
for(intx=0; x
for(inty=0; y
if(bitmap.getpixel(x,y )==color.RGB )0xff,0x 00,0x ff ) )
{
bitmap.setpixel(x,y,Color.TRANSPARENT );
}
}
}
但是,结果差不多。 使用不同的PorterDuffModes会使整个位图变得透明,或使目标像素变黑。
你有什么想法吗?