Android scratch card effect implementation code

This example shares the effect of Android scratch card for your reference. The specific contents are as follows

Android implements a picture on the bottom layer and a mask layer on the upper layer. Touch and slide to remove the mask according to the finger sliding path, which is similar to the scraping card of the lucky draw. Let's talk about the previous effect picture first:

Direct code:

XfermodeView. java

Xfermode has three subclasses: avoidxfermode specifies a color and tolerance that forces paint to avoid drawing on it (or only on it). Pixel XOR xfermode applies a simple pixel XOR operation when overwriting an existing color. Porterduffxfermode this is a very powerful conversion mode. You can use any of the 16 Porter Duff rules for image synthesis to control paint

How to interact with existing canvas images.

From above we can see porterduff Mode is an enumeration class with 16 enumeration values: 1 PorterDuff. Mode. What is drawn by clear is not submitted to the canvas. 2.PorterDuff. Mode. SRC display upper layer drawing picture 3 PorterDuff. Mode. DST display lower layer drawing picture 4 PorterDuff. Mode. SRC_ Over normal drawing shows that the upper and lower layers draw overlaps. 5.PorterDuff. Mode. DST_ Upper and lower layers of over are displayed. Displayed on the lower floor. 6.PorterDuff. Mode. SRC_ In takes two layers to draw the intersection. Display the upper layer. 7.PorterDuff. Mode. DST_ In takes two layers to draw the intersection. Displays the lower layer. 8.PorterDuff. Mode. SRC_ Out takes the upper layer and draws the non intersecting part. 9.PorterDuff. Mode. DST_ Out takes the lower layer and draws the non intersecting part. 10.PorterDuff. Mode. SRC_ Atop takes the non intersection part of the lower layer and the intersection part of the upper layer 11 PorterDuff. Mode. DST_ Atop takes the upper non intersection part and the lower intersection part 12 PorterDuff. Mode. XOR XOR: remove the intersection of two layers 13 PorterDuff. Mode. Darken takes all areas of the two layers, and the color of the intersection part is deepened by 14 PorterDuff. Mode. Lighten takes all of the two layers and lights up the intersection color 15 PorterDuff. Mode. Multi takes the color 16 after the overlapping part of the two layers is superimposed PorterDuff. Mode. Screen takes all the areas of the two layers, and the intersection part becomes transparent

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>