开启硬件加速之后,许多2D的绘制方法会抛出异常
2013-06-06 11:02
363 查看
需要注意的方法如下:
Canvas
Paint
Xfermodes
In addition, some operations behave differently with hardware acceleration enabled:
Canvas
do not apply to the clip rectangle
Paint
PorterDuffXfermode
blending against the framebuffer.
blending against the framebuffer.
blending against the framebuffer.
ComposeShader
a
如在Canvas.clipPath时会抛出异常
UnsupportedOperationException in GLES20Canvas.clipPath with hardware acceleration disabled on view
解决办法:在程序中通过反射禁掉硬件加速
private static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) {
try {
return clazz.getMethod(name, parameterTypes);
}
catch (NoSuchMethodException e) {
return null;
}
}
public static void disableHardwareAcceleration(View view) {
try {
Method setLayerTypeMethod = getMethod(View.class, "setLayerType", int.class,
Paint.class);
if (setLayerTypeMethod != null) {
int layerType = 1; // View.LAYER_TYPE_SOFTWARE
setLayerTypeMethod.invoke(view, layerType, null);
}
}
catch (Exception ignored) {
}
}
Canvas
clipPath()
clipRegion()
drawPicture()
drawTextOnPath()
drawVertices()
Paint
setLinearText()
setMaskFilter()
setRasterizer()
Xfermodes
AvoidXfermode
PixelXorXfermode
In addition, some operations behave differently with hardware acceleration enabled:
Canvas
clipRect():
XOR,
Differenceand
ReverseDifferenceclip modes are ignored. 3D transforms
do not apply to the clip rectangle
drawBitmapMesh(): colors array is ignored
Paint
setDither(): ignored
setFilterBitmap(): filtering is always on
setShadowLayer(): works with text only
PorterDuffXfermode
PorterDuff.Mode.DARKENwill be equivalent to
SRC_OVERwhen
blending against the framebuffer.
PorterDuff.Mode.LIGHTENwill be equivalent to
SRC_OVERwhen
blending against the framebuffer.
PorterDuff.Mode.OVERLAYwill be equivalent to
SRC_OVERwhen
blending against the framebuffer.
ComposeShader
ComposeShadercan only contain shaders of different types (a
BitmapShaderand
a
LinearGradientfor instance, but not two instances of
BitmapShader)
ComposeShadercannot contain a
ComposeShader
如在Canvas.clipPath时会抛出异常
UnsupportedOperationException in GLES20Canvas.clipPath with hardware acceleration disabled on view
解决办法:在程序中通过反射禁掉硬件加速
private static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) {
try {
return clazz.getMethod(name, parameterTypes);
}
catch (NoSuchMethodException e) {
return null;
}
}
public static void disableHardwareAcceleration(View view) {
try {
Method setLayerTypeMethod = getMethod(View.class, "setLayerType", int.class,
Paint.class);
if (setLayerTypeMethod != null) {
int layerType = 1; // View.LAYER_TYPE_SOFTWARE
setLayerTypeMethod.invoke(view, layerType, null);
}
}
catch (Exception ignored) {
}
}
相关文章推荐
- JAVA为什么子类继承父类方法之后,不能抛出比父类更多的异常?
- JAVA为什么子类继承父类方法之后,不能抛出比父类更多的异常?
- 1 开发一个注重性能的JDBC应用程序不是一件容易的事. 当你的代码运行很慢的时候JDBC驱动程序并不会抛出异常告诉你。 本系列的性能提示将为改善JDBC应用程序的性能介绍一些基本的指导原则,这其中的原则已经被许多现有的JDBC应用程序编译运行并验证过。 这些指导原则包括: 正确的使用数据库MetaData方法 只获取需要的数据 选用最佳性能的功能 管理连
- C#的WinForm程序应用了XP主题样式之后,抛出异常的解决方法
- gcc升级到4.8.2之后调试异常的处理方法
- 反射调用方法时抛出的异常的获取
- 在指定方法中抛出异常,在调用该方法的地方处理异常
- java 抛出异常处理的方法
- javah导出类的头文件抛出异常——java.lang.IllegalArgumentException: Not a valid class name(原因及解决方法)
- 写一个方法void triangle(int a,int b,int c),判断三个参数是否能构成一个三角形。如果不能则抛出异常IllegalArgumentException,显示异常信息:a,b,
- struts解决异常抛出的两种方法
- D3D中用3D方法绘制2D图象的例子
- Windows Phone抛出异常退出方法
- springboot springmvc 抛出全局异常解决方法
- 继承后方法抛出异常的问题
- 第六十二条:每个方法抛出的异常都要有文档
- 编写一个Cirle类,包括构造方法,求圆的面积和周长,如果圆的半径小于0则抛出异常,让用户必须处理,半径必须大于0才可以
- 开启硬件加速时Web页面绘制流程
- android用SAX解析xml文件时抛出org.apache.harmony.xml.ExpatParser$ParseException异常的解决方法
- 异常不管咋样,只要抛出了,不管是方法级别抛出,还是类级别抛出。终究有一个地方要对异常进行处理