Передача изображения с одной страницы на другую Windows Phone 7 - PullRequest
0 голосов
/ 29 июня 2011

Я пытаюсь передать изображение в элементе управления изображением одной страницы на другую. Например, у меня есть элемент управления изображением с именем «image1» в Page1.xaml , и я хочу, чтобы изображение, показанное в «image1», было передано / показано в Page2.xaml ink canvas, Можете ли вы помочь мне с кодированием делать это. Спасибо.

1 Ответ

1 голос
/ 29 июня 2011

Первая страница сохраняет изображение в изолированном хранилище в виде файла photo.jpg.Читайте на второй странице.

Страница 1:

public partial class Page1 : PhoneApplicationPage
{
    PhotoChooserTask PhotoChooser;
    int ImageWidth, ImageHeight;
    // Constructor
    public Page1()
    {
        InitializeComponent();

        ImageWidth = (int)PageImage.Width;
        ImageHeight = (int)PageImage.Height;

        PhotoChooser = new PhotoChooserTask();
        PhotoChooser.PixelWidth = ImageWidth;
        PhotoChooser.PixelHeight = ImageHeight;
        PhotoChooser.ShowCamera = true;

        PhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooser_Completed);
    }

    void PhotoChooser_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            IsolatedStorageFile Store = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream Stream = new IsolatedStorageFileStream("photo.jpg", FileMode.Create, FileAccess.Write, Store);

            WriteableBitmap myImage = new WriteableBitmap(ImageWidth, ImageHeight);
            myImage.SetSource(e.ChosenPhoto);
            PageImage.Source = myImage;
            PageImage.InvalidateArrange();
            myImage.SaveJpeg(Stream, ImageWidth, ImageHeight, 0, 100);

            Stream.Close();
        }
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        if (IsolatedStorageFile.GetUserStoreForApplication().FileExists("photo.jpg"))
        {
            IsolatedStorageFile Store = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream Stream = new IsolatedStorageFileStream("photo.jpg", FileMode.Open, FileAccess.Read, Store);

            WriteableBitmap myImage = new WriteableBitmap(ImageWidth, ImageHeight);
            myImage.LoadJpeg(Stream);

            PageImage.Source = myImage;
            PageImage.InvalidateArrange();
            Stream.Close();
        }
    }

    private void ToPage2Button_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
    }

    private void LoadButton_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        PhotoChooser.Show();
    }
}

Страница 2:

public partial class Page2 : PhoneApplicationPage
{
    int ImageWidth, ImageHeight;

    public Page2()
    {
        InitializeComponent();

        ImageWidth = (int)PageImage.Width;
        ImageHeight = (int)PageImage.Height;
    }

    private void BackButton_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        NavigationService.GoBack();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        if (IsolatedStorageFile.GetUserStoreForApplication().FileExists("photo.jpg"))
        {
            IsolatedStorageFile Store = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream Stream = new IsolatedStorageFileStream("photo.jpg", FileMode.Open, FileAccess.Read, Store);

            WriteableBitmap myImage = new WriteableBitmap(ImageWidth, ImageHeight);
            myImage.LoadJpeg(Stream);

            PageImage.Source = myImage;
            PageImage.InvalidateArrange();
            Stream.Close();
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...