Scratch (eraser) function under WP8

Source: Internet
Author: User
Tags transparent color

When it comes to scraping, the first thing we think about is the overlap of the top and bottom two (rectangles), and then the above image.

My idea is: by hand gestures, the place where the finger is going to become transparent, the bottom will be displayed.

So how do you make a picture transparent? This will be done with the pixels of the image.

First, the pixel of the image is an array of type int: int[], this array length is picture high (pixels) * Width (pixels)

For example: A picture of the aspect is 200pixel, 400pixel, then this array is int[80000]

For each element, the official document says Argb32[RGB24] (a refers to the alpha channel control transparency)

The RGB color of level 256 (0-255) can combine approximately 16.78 million colors, i.e. 256x256x256=16777216

That is, each element is: (-1: White)-----(-16777216: Black) 0 or another positive value is a transparent color

Pass

New

We get to be a one-dimensional array that we convert to a two-dimensional array for ease of operation.

 for (int0; i < ioriginalheight; i++) //Picture height {    for (int0 ; J < Ioriginalwidth; J + +) //Picture width    {        = originalwb.pixels[i * (ioriginalwidth) + j];    }}

After we touch the gesture, we're going to deal with the pixels.

: Suppose we length=1 (referring to the size of the touch after it)

If we select the red position, I'm going to make the square ( Green position) of the pixel with a distance of 1 on the edge of the red pixel transparent

We can get the start end row and column to the Green range.

Then just change the color of that pixel.

0; // gets the subscript of a neighboring pixel (i * l) + j

Assign a value to the picture at the end

Here is the demo under WP8: Remember: You need to download a picture online

Click to download

PS: But the effect is not very good, due to the use of a square (unfortunately WriteableBitmap does not have some methods under WPF)

If there is a better way, hope to tell me!

Scratch (eraser) function under WP8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.