[英]How to set a color filter for XWalkView?
I am currently working on my web browser Cornowser , which uses the Crosswalk engine, and I ran into a problem. 我目前正在使用我的网络浏览器Cornowser ,它使用Crosswalk引擎,我遇到了一个问题。 I want to implement color modes, as they are in UltimateBrowserProject.
我想实现颜色模式,就像它们在UltimateBrowserProject中一样。
But the color filters don't apply. 但滤色器不适用。 I tried setting the layer type and passing the
Paint
with the color filter. 我尝试设置图层类型并使用颜色过滤器传递
Paint
。
Here is the source code: 这是源代码:
// Handle color modes
public void drawWithColorMode() {
Logging.logd("Applying web render color mode...");
RenderColorMode.ColorMode cm = CornBrowser.getBrowserStorage().getColorMode();
Paint paint = new Paint();
final float[] negativeColor = {
-1.0f, 0, 0, 0, 255, // Red
0, -1.0f, 0, 0, 255, // Green
0, 0, -1.0f, 0, 255, // Blue
0, 0, 0, 1.0f, 0 // Alpha
};
final float[] darkColor = {
1f, 0, 0, 0, -255,
0, 1f, 0, 0, -255,
0, 0, 1f, 0, -255,
0, 0, 0, 1f, 0
};
final float[] invertColor = {
-1f, 0, 0, 0, 0,
0, -1f, 0, 0, 0,
0, 0, -1f, 0, 0,
0, 0, 0, 1f, 0
};
Logging.logd("Found color mode: " + cm.mode);
switch(cm.mode) {
case RenderColorMode.ColorMode.NORMAL:
Logging.logd("Applying normal color mode");
paint.setColorFilter(null);
break;
case RenderColorMode.ColorMode.DARK:
Logging.logd("Applying dark mode");
paint.setColorFilter(new ColorMatrixColorFilter(darkColor));
break;
case RenderColorMode.ColorMode.NEGATIVE:
Logging.logd("Applying negative mode");
paint.setColorFilter(new ColorMatrixColorFilter(negativeColor));
break;
case RenderColorMode.ColorMode.INVERT:
Logging.logd("Applying inverted mode");
paint.setColorFilter(new ColorMatrixColorFilter(invertColor));
break;
case RenderColorMode.ColorMode.GREYSCALE:
Logging.logd("Applying greyscale");
ColorMatrix m = new ColorMatrix();
m.setSaturation(0);
paint.setColorFilter(new ColorMatrixColorFilter(m));
break;
default:
Logging.logd("Warning: Unknown color mode " + cm.mode + ".");
break;
}
Logging.logd("Setting layer type...");
setLayerType(LAYER_TYPE_HARDWARE, paint);
}
I also tried it by overriding draw(canvas)
but it's the same result. 我也通过覆盖
draw(canvas)
尝试了它,但它是相同的结果。
Does anyone know how to set a color filter for XWalkView? 有谁知道如何为XWalkView设置颜色过滤器?
Thanks in advance! 提前致谢!
UPDATE: 更新:
It seems to be that SurfaceView
doesn't support color filters. 似乎
SurfaceView
不支持彩色滤镜。 How to do it anyways? 怎么办呢?
UPDATE 2: Seems that this question is not getting so much attention... I edited my source code, how it should work, but it doesn't work, please check it, logcat gives me following output: 更新2:似乎这个问题没有得到如此多的关注......我编辑了我的源代码,它应该如何工作,但它不起作用,请检查一下,logcat给我以下输出:
D/Cornowser: Applying web render color mode...
D/Cornowser: Found color mode: 2
D/Cornowser: Applying negative mode
D/Cornowser: Setting layer type...
Final update: I actually got it working by using JavaScript. 最后更新:我实际上是通过使用JavaScript来实现的。 If you want to know how I solved it, look right here .
如果你想知道我是如何解决它的,那就看看吧 。
Override the draw(Canvas) method 覆盖draw(Canvas)方法
write the above source code 写上面的源代码
At the end of the draw() method call invalidate() 在draw()方法结束时调用invalidate()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.