更改 Windows Phone 应用程序的可写位图对象



所有,我有一个基本的Windows 7 Phone应用程序,我刚刚完成了一个裁剪页面,用户可以在其中裁剪用手机摄像头拍摄的图像。在cameraCapTask_Completed事件中,我设置了应用程序的全局WritableBitmap

public static WriteableBitmap capturedImage;

如下

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);

当我拍摄照片时,我会将其传递到CropProcessPage构造函数中的裁剪页面,我会通过在页面中设置图像

public CropProcessPage()
{
    InitializeComponent();
    // Set the text and display captured image.
    imageMain.Source = App.capturedImage;

这是有效的。但是,当我返回主页并重新拍摄/拍摄另一张图像时,当我尝试拍摄新图像时,会显示旧图像(拍摄的第一张图像)。构造函数被调用,相机捕获的事件(设置新图像)也被调用。我在这里做错了什么?

在CropProcessPage 中

移动线路

imageMain.Source = App.capturedImage;

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

最新更新