好的,所以我使用马克告诉我的不同技术找到了自己的答案。我使用以下伪代码:
*s = Read-File-Into-Image("/path/to/image")*g = Convert-To-Gray-Scale(s)*i = Invert-Colors(g)*b = Apply-Gaussian-Blur(i)*result = Color-Dodge-Blend-Merge(b,g)
前四种方法很容易在Internet上找到,但是在最后一种方法中,我找不到很多信息,甚至没有源代码。因此,我搜索了PS是如何做到的,并在c
++中找到了以下公式:
((uint8)((B == 255) ? B:min(255, ((A << 8 ) / (255 - B)))))
然后我使用以下代码将其转换为Java:
private int colordodge(int in1, int in2) { float image = (float)in2; float mask = (float)in1; return ((int) ((image == 255) ? image:Math.min(255, (((long)mask << 8 ) / (255 - image)))));}public Bitmap ColorDodgeBlend(Bitmap source, Bitmap layer) { Bitmap base = source.copy(Config.ARGB_8888, true); Bitmap blend = layer.copy(Config.ARGB_8888, false); IntBuffer buffbase = IntBuffer.allocate(base.getWidth() * base.getHeight()); base.copyPixelsToBuffer(buffbase); buffbase.rewind(); IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight()); blend.copyPixelsToBuffer(buffBlend); buffBlend.rewind(); IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); buffOut.rewind(); while (buffOut.position() < buffOut.limit()) { int filterInt = buffBlend.get(); int srcInt = buffbase.get(); int redValueFilter = Color.red(filterInt); int greenValueFilter = Color.green(filterInt); int bluevalueFilter = Color.blue(filterInt); int redValueSrc = Color.red(srcInt); int greenValueSrc = Color.green(srcInt); int bluevalueSrc = Color.blue(srcInt); int redValueFinal = colordodge(redValueFilter, redValueSrc); int greenValueFinal = colordodge(greenValueFilter, greenValueSrc); int bluevalueFinal = colordodge(bluevalueFilter, bluevalueSrc); int pixel = Color.argb(255, redValueFinal, greenValueFinal, bluevalueFinal); buffOut.put(pixel); } buffOut.rewind(); base.copyPixelsFromBuffer(buffOut); blend.recycle(); return base;}
如果可以改进代码,请在下面发布新的答案或评论。谢谢!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)