更改Windows Phone应用程序WriteableBitmap对象

时间:2012-04-05 14:42:18

标签: c# image windows-phone-7 image-capture

全部,我有一个基本的Windows 7手机应用程序,我刚刚完成一个裁剪页面,用户可以裁剪用手机摄像头拍摄的图像。在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;

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

1 个答案:

答案 0 :(得分:1)

在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;
}