Simple implementation of Android scratch card effect

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

1、 Xfermode

By using xfermode, the pixels of the drawn graphics and the pixels at the corresponding position on the canvas are mixed according to certain rules to form new pixels, and then updated to the canvas to form the final graphics. When using, it is realized through paint.setxfermode.

2、 Mixed mode classification

Porterduff is a basic technique used to describe digital image synthesis. Any 2D image can be synthesized by combining porterduff operations.

1. SRC class, the source image is displayed first. SRC_ When in processes the image intersection area, it is affected by the alpha value of the target image. When our target image is a blank pixel, the source image will also become blank. In short, it is to use the transparency of the target image to change the transparency and saturation of the source image. When the transparency of the target image is 0, the source image will not be displayed. SRC_ Out uses the complementary value of the transparency of our target image to change the transparency and saturation of the source image. When the transparency of the target image is opaque, the source image will not be displayed. SRC_ Atop SRC when transparency is 100% and 0%_ In and SRC_ Atop is general. When the transparency is not the above two values, SRC_ Atop ratio SRC_ The saturation of the in source image increases and becomes brighter.

2. DST class, the priority is to display the target image. DST_ In changes the transparency and saturation of the target image with the transparency of the source image at the time of intersection. When the transparency of the source image is 0, the target image is not displayed at all.

3. For other overlay effects, multiple can take out the outline of the picture and lighten the effect.

3、 Scraping card effect

1. Renderings

2. The implementation idea uses the pattern Src in porterduffxfermode_ Out: first draw the final rendered picture and save the layer, then render the track of finger movement to the canvas, and draw the target picture to the canvas. Finally, use the supplement value of the transparency of the target picture to change the transparency value of the source picture and display the final rendered picture on the screen.

3. Code example

This 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
分享
二维码
< <上一篇
下一篇>>