mupdf:android 库:如何反转颜色或更改为夜间模式
mupdf: android library: How to invert the colors or change to night mode
如果有人使用 mupdf
库 android 知道如何反转背景。我想在 ui
中添加一个按钮
很简单。在 PageView 中渲染位图只是反转位图。
mEntire.setImageBitmap(invert(mEntireBm));
mPatch.setImageBitmap(invert(mPatchBm));
这里是反转位图的方法。
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;
}
如果有人使用 mupdf
库 android 知道如何反转背景。我想在 ui
很简单。在 PageView 中渲染位图只是反转位图。
mEntire.setImageBitmap(invert(mEntireBm));
mPatch.setImageBitmap(invert(mPatchBm));
这里是反转位图的方法。
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;
}