Skip to main content

Hot to work around Canvas.clipPath() that is not supported in android any more



From android 3.0 the clipPath() method is no longer supported in devices with hardware acceleration turned on.(Read this article for more details).





I am working with canvas and I need to draw rounded image. Any ideas about how can I do that?





*I can't turn the hardware acceleration off, I am looking for other solution.





Answered: Tnx @Malcolm for your answer. I found a good example that demonstrate this technique , it's basically a mask.


Comments

  1. It is not no longer supported, it is only not available with hardware acceleration turned on. The article you've mentioned contains a clue:


    If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by calling setLayerType(View.LAYER_TYPE_SOFTWARE, null). This way, you can still take advantage of hardware acceleratin everywhere else. See Controlling Hardware Acceleration for more information on how to enable and disable hardware acceleration at different levels in your application.


    The main idea here is to disable hardware acceleration in the part of the application where you need to use the unsupported methods. You can do it for a particular view, there's no need to turn it off completely for the whole application.

    If you don't want to turn off hardware acceleration, then I would suggest using Porter-Duff modes. You can create a bitmap with a circle in it, then draw your image onto the canvas using such a mode that would clip your image to the original content.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?