[英]mupdf: android library: How to invert the colors or change to night mode
If anyone using mupdf
library for android know how to invert the background.如果有人使用 android 的
mupdf
库知道如何反转背景。 I want to add a button to the ui
我想在
ui
添加一个按钮
It's very simple.这很简单。 In PageView while rendering bitmap just invert the bitmap.
在 PageView 中渲染位图时只是反转位图。
mEntire.setImageBitmap(invert(mEntireBm));
mPatch.setImageBitmap(invert(mPatchBm));
Here is how you can invert a bitmap.以下是反转位图的方法。
private Bitmap invert(Bitmap src) {
int height = src.getHeight();
int width = src.getWidth();
Bitmap bitmap = Bitmap.createBitmap(width, height, src.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
ColorMatrix matrixGrayscale = new ColorMatrix();
matrixGrayscale.setSaturation(0);
ColorMatrix matrixInvert = new ColorMatrix();
matrixInvert.set(new float[]
{
-1.0f, 0.0f, 0.0f, 0.0f, 255.0f,
0.0f, -1.0f, 0.0f, 0.0f, 255.0f,
0.0f, 0.0f, -1.0f, 0.0f, 255.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
});
matrixInvert.preConcat(matrixGrayscale);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrixInvert);
paint.setColorFilter(filter);
canvas.drawBitmap(src, 0, 0, paint);
// src.recycle();
return bitmap;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.