我正在编写一个程序,允许用户比较2张照片,1作为样本颜色和其他要编辑。我将从第一个中收集像素信息,然后应用以下方法编辑后一个。
图片来源:http://www.flickr.com/photos/92325795@N02/8392038944/in/photostream
我的照片正在更新,尽管有质量/噪音/颜色,但到处都有奇怪的颜色。有没有人知道我该怎么做才能移除它?或者更好地改进我正在使用的方法?代码如下:
输入是要编辑的位图,inColor是要编辑的照片中鼻子的颜色,reqcolor是示例/最佳照片中我的鼻子的颜色。
public Bitmap shiftRGB(Bitmap input, int inColor, int reqColor){
int deltaR = Color.red(reqColor) - Color.red(inColor);
int deltaG = Color.green(reqColor) - Color.green(inColor);
int deltaB = Color.blue(reqColor) - Color.blue(inColor);
//--how many pixels ? --
int w = input.getWidth();
int h = input.getHeight();
//-- change em all! --
for (int i = 0 ; i < w; i++){
for (int j = 0 ; j < h ; j++ ){
int pixColor = input.getPixel(i,j);
//-- colors now ? --
int inR = Color.red(pixColor);
int inG = Color.green(pixColor);
int inB = Color.blue(pixColor);
if(inR > 255){ inR = 255;}
if(inG > 255){ inG = 255;}
if(inB > 255){ inB = 255;}
if(inR < 0){ inR = 0;}
if(inG < 0){ inG = 0;}
if(inB < 0){ inB = 0;}
//-- colors then --
input.setPixel(i,j,Color.argb(255,inR + deltaR,inG + deltaG,inB + deltaB));
}
}
return input;
}非常感谢你的帮助!我无法表达我的感激之情,只能提前说一声谢谢!
发布于 2013-01-20 03:54:46
该函数似乎如预期的那样工作。
然而,我注意到的一件事是,在实际设置新像素的最终输出之前,您正在使用"if“情况来验证边界。
if(inR > 255){ inR = 255;}
if(inG > 255){ inG = 255;}
if(inB > 255){ inB = 255;}
if(inR < 0){ inR = 0;}
if(inG < 0){ inG = 0;}
if(inB < 0){ inB = 0;}
input.setPixel(i,j,Color.argb(255,inR + deltaR,inG + deltaG,inB + deltaB));
我相信这就是你真正想要做的。
inR += deltaR
inG += deltaG
inB += deltaB
if(inR > 255){ inR = 255;}
if(inG > 255){ inG = 255;}
if(inB > 255){ inB = 255;}
if(inR < 0){ inR = 0;}
if(inG < 0){ inG = 0;}
if(inB < 0){ inB = 0;}
input.setPixel(i,j,Color.argb(255,inR,inG,inB));
https://stackoverflow.com/questions/14421427
复制相似问题