如何将ImageView中的黑色替换为透明颜色(或其他颜色)?
我使用毕加索从web上加载图像:
Picasso.with(getContext()).load("www.abc.com/a.png").into(myImageView);
目前它看起来是这样的:
图像本身包含黑色背景,我想将其删除。我试过使用myImageView.setColorFilter(Color.BLACK);
,但它似乎不起作用。
发布于 2017-07-07 16:21:51
Andy Developer's answer提供了帮助,但我不得不手动将黑色像素转换为我喜欢的像素。它正在工作,尽管我不确定这是否是最好的方法。
Picasso.with(getContext()).load(IMAGE_URL).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)
{
Bitmap copy = bitmap.copy(bitmap.getConfig(),true);
int [] allpixels = new int [copy.getHeight()*copy.getWidth()];
copy.getPixels(allpixels, 0, copy.getWidth(), 0, 0, copy.getWidth(), copy.getHeight());
int replacementColor = Color.parseColor("#34495E");
for(int i = 0; i < allpixels.length; i++) {
if(allpixels[i] == Color.BLACK)
allpixels[i] = replacementColor;
}
copy.setPixels(allpixels, 0, copy.getWidth(), 0, 0, copy.getWidth(), copy.getHeight());
myImageView.setImageBitmap(copy);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) { }
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) { }
});
发布于 2017-07-07 10:21:25
你可以试试这个。
Picasso.with(this).load("Your URL").into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from)
{
bitmap.eraseColor(Color.argb(AAA,RRR,GGG,BBB));
OR
bitmap.eraseColor(getResources().getColor(R.color.myColor));
imageView.setBackground(new BitmapDrawable(bitmap));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
https://stackoverflow.com/questions/44968173
复制