简体   繁体   中英

Changing a Windows Phone Application's WritableBitmap Object

All, I have a basic Windows 7 Phone application and I have just finished a crop page, where the users are able to crop an image taken with the phones camera. In the cameraCapTask_Completed event I set the App's global WritableBitmap

public static WriteableBitmap capturedImage;

as follows

void cameraCapTask_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
    {
        // Take JPEG stream and decode into a WriteableBitmap object.
        App.capturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);

When I take a picture I then pass it to the cropping page in the CropProcessPage constructor I set the Image in the page via

public CropProcessPage()
{
    InitializeComponent();

    // Set the text and display captured image.
    imageMain.Source = App.capturedImage;

This works. However, when I go back to the Main Page and retake/take another image, when I try to the new image, the old image (the first one taken) is shown. The constructor is being called and so is the camera captured event (setting the new image). What am I doing wrong here?

In CropProcessPage

move line

imageMain.Source = App.capturedImage;

to

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
// Set the text and display captured image.
    imageMain.Source = App.capturedImage;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM