存储由用户C#

时间:2015-10-19 20:07:22

标签: c# image windows-phone-8 graphics

我有一个Windows Phone 8应用程序,允许用户绘制图像。我希望能够存储用户绘制到图像上的路径。

因此,例如,用户绘制一条贯穿整个图像的线条。我想存储整个路径,以便当用户离开应用程序并返回时,他们可以单击一个按钮,应用程序将重绘之前的路径到图像上。

我的问题是:如何存储用户绘制的线条的整个坐标?

这是我目前的代码:

public partial class MainPage : PhoneApplicationPage
{

    // Constructor
    public MainPage()
    {
        InitializeComponent();
        this.Loaded += MainPage_Loaded;
    }
    private WriteableBitmap writeableBmp;
    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        // Init WriteableBitmap
        writeableBmp = new WriteableBitmap(OrginalImage, null);
        writeableBmp.Invalidate();
    }
    private void AlterButton_Click(object sender, RoutedEventArgs e)
    {
        ImagePixelsAlter(new ExecuteAction((bitmap) => { AlterImage.Source = bitmap; }));
    }  
    public void ImagePixelsAlter(ExecuteAction action)
    {
        WriteableBitmap writeableBitmap = new WriteableBitmap(OrginalImage, null);
        for (int i = 0; i < writeableBitmap.Pixels.Count(); i++)
        {
            if (i % 3 == 0)
            {
                writeableBitmap.Pixels.SetValue(-95756, i);
            }
        }

        action(writeableBitmap);
    }
    public delegate void ExecuteAction(WriteableBitmap bitmap);    
    private void Image_MouseMove(object sender, MouseEventArgs e)
    {
        var mp = GetMousePoint(e);
        writeableBmp.FillRectangle(mp.X, mp.Y, mp.X +5, mp.Y +5, Colors.Red);
        OrginalImage.Source = writeableBmp;
    }
    private ControlPoint GetMousePoint(MouseEventArgs e)
    {
        return new ControlPoint(e.GetPosition(OrginalImage));
    }
}

0 个答案:

没有答案