如何通过手指触摸屏幕擦除Windows手机中图像的特定像素

时间:2014-10-22 12:21:00

标签: windows-phone-8

我是Windows Phone编程新手,我遇到了问题,过去两天我一直在浏览互联网,但一无所获。

我在写作和应用程序,其中我有两个图像一个在另一个,我需要"擦除"手指顶部,有点像使用橡胶,所以我可以看到下面的图片。我一般都画了画,但现在还不是我需要的。我找到了一个类似的例子,但由于图书馆的不同,它在手机上不起作用。有人可以帮我找一些我可以使用的东西吗?或者可以展示什么?

我找到了像this这样的东西,如果我能在windows phone 8中做到这样的话会很棒

请注意,我使用的是Microsoft Visual Studio Express 2012

1 个答案:

答案 0 :(得分:0)

经过几天的工作,我设法得到了可擦除层。

 //Created by Kamil Sokołowski on 01.11.14
//Windows Phone 7.1 Build on Microsoft Visual Studio Express 2012 for Windows Phone


public partial class MainPage : PhoneApplicationPage
    {
        public BitmapImage mainImage;
        private WriteableBitmap writeableBitmap;
        private bool isRubbing;
        private SolidColorBrush brush;
        private Point currentPoint;
        private Point oldPoint;
        private bool touchedFirst;
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            Canvas mainCanwas = new Canvas();
            drawBackgroundLayer(new Uri("main.png", UriKind.RelativeOrAbsolute));
            drawImageLayer(new Uri("para.png", UriKind.RelativeOrAbsolute));
            touchedFirst = true;
        }

        public void drawBackgroundLayer(Uri uri)
        {
            BitmapImage bgi = new BitmapImage();
            bgi.UriSource = uri;
            BackGroundImage.Source = bgi;
        }

        public void drawImageLayer(Uri uri)
        {
            mainImage = new BitmapImage();
            mainImage.UriSource = uri;
            MyImage.Source = mainImage;
        }

        private void Tap_leftButtonDown(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (touchedFirst)
            {

                WriteableBitmap wb = new WriteableBitmap(mainImage);

                Color color = new Color();
                color.A = 0;
                color.R = 33;
                color.G = 34;
                color.B = 255;
                brush = new SolidColorBrush();
                brush.Color = color;
                touchedFirst = false;
                writeableBitmap = wb;
            }
            isRubbing = true;
            oldPoint = currentPoint;
            currentPoint = e.GetPosition(MyImage);
        }

        private void Mouse_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (isRubbing)
            {
                oldPoint = currentPoint;
                currentPoint = e.GetPosition(MyImage);
                for (int i = 0; i < 40; i++)
                {
                    for (int a = 0; a < 40; a++)
                    {
                        writeableBitmap.DrawLine((int)currentPoint.X + i, (int)currentPoint.Y + a, (int)oldPoint.X + i, (int)oldPoint.Y + a, brush.Color);
                    }
                }
                MyImage.Source = writeableBitmap;
            }
        }

        private void ButtonLetGo(object sender, MouseButtonEventArgs e)
        {
            isRubbing = false;
            MyImage.Source = writeableBitmap;
        }
    }
}

//要使其工作,您需要下载WiritableBitmapEx表单NuGet