1
我必須將圖像轉換爲android中的鉛筆素描。將圖像轉換爲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
請在此幫助我。
的Catalano的框架:HTTP://www.codeproject.com/Articles/656059/Catalano-Framework;前面的問題:http://stackoverflow.com/questions/9826273/photo-image-to-sketch-algorithm – user3217900