使用canvas.clipPath来裁剪时部分机型出现问题

使用canvas.clipPath来裁剪时部分机型出现问题

	项目中用canvas.clipPath来进行裁剪画布,出现在部分机型裁剪出来的效果一直是矩形的bug。
	出现的原因:默认开启硬件加速导致的bug。
	解决方案:关闭硬件加速。在配置文件该activity的声明中添加android:hardwareAccelerated="false"即可解决问题
参考链接:http://stackoverflow.com/questions/16889815/canvas-clippath-only-works-on-android-emulator
	  http://www.cnblogs.com/lonelyDog/archive/2012/07/12/2588477.html
 
关于 Hardware Acceleration

1、不同层级的加速:

Application<applicationandroid:hardwareAccelerated="true" ...>;
Activity<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
</application>;
Window getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);;
ViewmyView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);;

2、如何判断是否开启了硬件加速

在绘制之前,你必须做该测试 Canvas.isHardwareAccelerated() 替代View.isHardwareAccelerated() 在必要时。

View.isHardwareAccelerated() ;//returns true if the View is attached to a hardware accelerated window.
Canvas.isHardwareAccelerated();// returns true if the Canvas is hardware accelerated;

3、开启硬件加速之后,许多2D的绘制方法会抛出异常:
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, Difference and ReverseDifference clip 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.DARKEN will be equivalent to SRC_OVER when blending against the framebuffer.
PorterDuff.Mode.LIGHTEN will be equivalent to SRC_OVER when blending against the framebuffer.
PorterDuff.Mode.OVERLAY will be equivalent to SRC_OVER when blending against the framebuffer.
ComposeShader
ComposeShader can only contain shaders of different types (a BitmapShader and a LinearGradient for instance, but not two instances of BitmapShader )
ComposeShader cannot contain a ComposeShader
 
 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值