简体   繁体   English

Windows Phone 8.1 Javascript应用程序-使用相机

[英]Windows Phone 8.1 Javascript Application - Use Camera

well, I have an existing HTML5 Application which should be ported to Windows Phone 8.1. 好吧,我有一个现有的HTML5应用程序,应将其移植到Windows Phone 8.1。 The existing applications needs some native access for sending mails, writing/reading files to/from the storage and taking pictures. 现有应用程序需要一些本机访问权限,以发送邮件,向存储设备写入文件/从存储设备读取文件以及拍照。

In my solution I have a Javascript Windows Phone 8.1 Application and a Windows Phone 8.1 Runtime Component. 在我的解决方案中,我有一个Javascript Windows Phone 8.1应用程序和一个Windows Phone 8.1运行时组件。 I already managed File/E-Mail Access through the Runtime Component. 我已经通过运行时组件管理文件/电子邮件访问。 ( Windows.ApplicationModel.* ) Windows.ApplicationModel.*

I'm stuck which the Camera. 我被卡在哪个相机上。 The goal is: 目标是:

  • Javascript Call "takePicture(callback)" JavaScript调用“ takePicture(callback)”
  • Natively take a picture (How?!) 本机拍照(如何?!)
  • Save it to the storage 保存到存储
  • Execute callback with data/file 使用数据/文件执行回调

I didn't find any real approach yet. 我还没有找到任何真正的方法。 How should I do this? 我应该怎么做?

What I tried so far: 到目前为止我尝试过的是:

public async void takePicture(PhotoSuccessCallback scb, PhotoErrorCallback ecb)
    {
        var x = new MediaCapture();
        var settings = new MediaCaptureInitializationSettings();
        settings.PhotoCaptureSource = PhotoCaptureSource.Photo;
        await x.InitializeAsync(settings);
        await x.StartPreviewAsync();
    }

This code snippet is crashing while StartPreviewAsync() with an unhelpful/generic exception. StartPreviewAsync()出现无用/通用异常时,此代码段崩溃。 Just to be clear, I don't really want to do this myself, there has to be an easy solution, right? 明确一点,我真的不想自己做,必须有一个简单的解决方案,对吗?

If I can't use this code, is it possible to navigate to a other view to manage this? 如果我无法使用此代码,是否可以导航到其他视图进行管理?

I have to admit, i'm pretty confused with all this stuff. 我必须承认,我对所有这些东西都很困惑。

Thanks. 谢谢。

Before you can start the preview, you need to assign the MediaCapture as the source to a control that can display your preview. 开始预览之前,您需要将MediaCapture分配为可以显示预览的控件的源。

I believe in JavaScript it would be something along the lines of: 我相信使用JavaScript可以达到以下目的:

var previewVidTag = document.getElementById("cameraPreview");
var previewUrl = URL.createObjectURL(x);
previewVidTag.src = previewUrl;
previewVidTag.play();

previewVidTag.addEventListener("playing", function () {
    // preview has started
});

And your HTML should have something like this: 而且您的HTML应该具有以下内容:

<video id="cameraPreview" class="cameraPreview"></video>

I believe you should be able to reference the Windows 10 CameraStarterKit SDK sample to get you started. 我相信您应该能够参考Windows 10 CameraStarterKit SDK示例来入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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