[英]Android - how to place color on Bitmap?
我有一張圖片( http://imgur.com/lIfzpWB.png ),該圖片是通過Bitmap.decodeFile(path);
打開的Bitmap.decodeFile(path);
。 但是,如何使用位圖來獲得這張圖片( http://imgur.com/GHltevM.png )? 我想我需要在位圖上應用某種顏色的蒙版。 我該怎么做?
我使用以下代碼來實現我的UPD :
image.setImageDrawable(convert(original, 0x7F00FF00));
public BitmapDrawable convert(Bitmap src, int color) {
BitmapDrawable temp = new BitmapDrawable(src);
temp.setColorFilter(new LightingColorFilter(0, color));
return temp;
}
UPD我完成了代碼工作! 我剛剛用new LightingColorFilter(color, 0)
替換了new LightingColorFilter(0, color)
new LightingColorFilter(color, 0)
。 謝謝大家的幫助!
嘗試這樣的事情。
Bitmap bitmap = Bitmap.decodeFile(path);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColorFilter(new LightingColorFilter(0, 0x005500));
canvas.drawPaint(paint);
這應該可以實現您想要的功能(我還沒有嘗試過),盡管可能必須針對所要實現的效果調整lightingColorFilter的值。
您需要刪除綠色通道。
您可以將文件作為名為“imagè”的變量作為緩沖圖像打開,然后使用以下代碼:
for(int i=0;i<image.getWidth();i++)
for(int j=0;j<image.getHeight();j++){
Color c=new Color(image.getRGB(i,j));
int pixel=c.getRed()<<16|c.getBlue();
image.setRGB(pixel);
}
生成的“imagè”將是沒有綠色通道的圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.