可能为时已晚,但我只想分享一种快速锐化图像的方法。
public static Bitmap doSharpen(Bitmap original, float[] radius) {
Bitmap bitmap = Bitmap.createBitmap(
original.getWidth(), original.getHeight(),
Bitmap.Config.ARGB_8888);
RenderScript rs = RenderScript.create(yourContext);
Allocation allocIn = Allocation.createFromBitmap(rs, original);
Allocation allocOut = Allocation.createFromBitmap(rs, bitmap);
ScriptIntrinsicConvolve3x3 convolution
= ScriptIntrinsicConvolve3x3.create(rs, Element.U8_4(rs));
convolution.setInput(allocIn);
convolution.setCoefficients(radius);
convolution.forEach(allocOut);
allocOut.copyTo(bitmap);
rs.destroy();
return bitmap;
}
这是我创建的 3 种不同的锐化类型:
// low
private static void loadBitmapSharp() {
float[] sharp = { -0.60f, -0.60f, -0.60f, -0.60f, 5.81f, -0.60f,
-0.60f, -0.60f, -0.60f };
//you call the method above and just paste the bitmap you want to apply it and the float of above
yourbitmap = doSharpen(getbitmap, sharp));
}
// medium
private static void loadBitmapSharp1() {
float[] sharp = { 0.0f, -1.0f, 0.0f, -1.0f, 5.0f, -1.0f, 0.0f, -1.0f,
0.0f
};
//you call the method above and just paste the bitmap you want to apply it and the float of above
yourbitmap = doSharpen(getbitmap, sharp));
}
// high
private static void loadBitmapSharp2() {
float[] sharp = { -0.15f, -0.15f, -0.15f, -0.15f, 2.2f, -0.15f, -0.15f,
-0.15f, -0.15f
};
//you call the method above and just paste the bitmap you want to apply it and the float of above
yourbitmap = doSharpen(getbitmap, sharp));
}
您也可以将它们直接应用到没有空白的位图上,它快速简单并且效果很好!