我必须将图像转换为 android 中的铅笔素描。
我使用了前面一个问题中提到的 cataleno 框架和 colorDodge 函数的概念。
这是我的功能:
public void onBwClick(View v) {
Bitmap bm = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
FastBitmap fb = new FastBitmap(bm);
Grayscale g = new Grayscale();
g.applyInPlace(fb);
Invert i = new Invert();
i.applyInPlace(fb);
GaussianBlur gb = new GaussianBlur();
gb.applyInPlace(fb);
FastBitmap xb = new FastBitmap(bm);
Grayscale gs = new Grayscale();
g.applyInPlace(xb);
Bitmap result = colorDodgeBlend(fb.toBitmap(), xb.toBitmap());
mImageView.setImageBitmap(result);
}
这是 colorDodgeBlend 函数:
public Bitmap colorDodgeBlend(Bitmap source, Bitmap layer) {
Log.d("", "logger enter colorDodgeBlend");
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);
float[] hsv = new float[3];
Color.colorToHSV(pixel, hsv);
hsv[1] = 0.0f;
float top = VALUE_TOP; // Setting this as 0.95f gave the best result so far
if (hsv[2] <= top) {
hsv[2] = 0.0f;
} else {
hsv[2] = 1.0f;
}
pixel = Color.HSVToColor(hsv);
buffOut.put(pixel);
}
buffOut.rewind();
base.copyPixelsFromBuffer(buffOut);
blend.recycle();
Log.d("", "logger executed colorDodgeBlend");
return base;
}
最后这是我得到的输出:!https://drive.google.com/file/d/0B9LDDNqlgTC1U3E3QXdiejk1Q28/edit?usp=sharing
这就是我想要的:!https://drive.google.com/file/d/0B9LDDNqlgTC1QkFPSmJFOXMyaUU/edit?usp=sharing
请帮我解决这个问题。