【问题标题】:Changing a Windows Phone Application's WritableBitmap Object更改 Windows Phone 应用程序 WriteableBitmap 对象
【发布时间】:2012-04-19 07:41:09
【问题描述】:

所有,我有一个基本的 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;

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

【问题讨论】:

  • 当我尝试使用新图像时,会显示旧图像(第一个拍摄的图像)。所以把它处理掉;)
  • 我已经尝试过这样做,但当然没有Dispose() 方法;那我该怎么办?如果是,使用Invalidate(),如何使用?
  • null 怎么样?在全局阶段将其定义为 null
  • 不起作用。在重新分配之前,我已将其设置为 null。就好像App对象(WritableBitmap)一旦设置就无法更改!?
  • 是的,我认为这是错误.. 所以删除 App.capturedImage 仅使用 imageMain.Source

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


【解决方案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;
}

【讨论】:

  • 我发现使用模拟器时显示的图像总是一样的。也许我应该在问题中这么说;也就是说,我正在使用模拟器来捕获图像。在这种情况下,这是编辑器的常见错误/功能吗?对不起,如果我浪费了你的时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-31
  • 2011-05-19
  • 1970-01-01
相关资源
最近更新 更多