1

我已通过 NuGet 将 WriteableBitmapExtension 添加到我的 Windows Phone 8.1 WinRT 应用程序中。我具有从相机捕获图像并将其保存到图片库的功能。我在保存之前尝试旋转捕获的图像,我在这里找到了解决方案 WriteableBitmap crash program without message? . 在模拟器上一切正常,但是当我在诺基亚 Lumia 630 上运行我的应用程序时,它在没有调试器消息的情况下拍照后崩溃了几秒钟。谁能帮我解决这个问题?这是我的拍照代码:

public WriteableBitmap Image
   {
        get
        {
            return this.image;
        }

        set
        {
            this.image = value;
            this.RaisePropertyChanged(() => this.Image);
        }
    }

private async void TakePhoto()
        {
            using (var stream = new InMemoryRandomAccessStream())
            {
                var imgEncodingProperties = ImageEncodingProperties.CreateJpeg();
                var img = BitmapFactory.New(640, 480);
                await this.MediaCapture.CapturePhotoToStreamAsync(imgEncodingProperties, stream);
                stream.Seek(0);
                img.SetSource(stream);
                WriteableBitmapExtensions.DrawLine(img, 10, 10, 300, 300, Colors.Black);
                this.Image = img.Rotate(90); 
                this.TurnOffCaptureMode();
            }  
        }

private void TurnOffCaptureMode()
        {
            this.MediaCapture.StopPreviewAsync();
            this.IsInCaptureMode = false;
        }
4

1 回答 1

0

替代解决方案在这里。 1 打开文件纠察队使用内置相机拍照。

 var openPicker = new FileOpenPicker();
    openPicker.ContinuationData["Action"] = "SendPicture";
    openPicker.FileTypeFilter.Add(".jpg");
    openPicker.FileTypeFilter.Add(".png");
    openPicker.PickSingleFileAndContinue();

***2. In app.xaml.cs you will get captured image. as below.***


    public void Continue(IContinuationActivatedEventArgs args)
{
    if(args.Kind == ActivationKind.PickFileContinuation)
    {
        var openPickerContinuationArgs = args as FileOpenPickerContinuationEventArgs;

        // Recover the "Action" info we stored in ContinuationData
        string action = (string) openPickerContinuationArgs.ContinuationData["Action"];

        if(openPickerContinuationArgs.Files.Count > 0)
        {
            // TODO: Get the files here
        }
        else
        {
            // TODO: Write code here to handle picker cancellation.
        }
    }
}
于 2015-05-11T18:14:25.647 回答