开发者

Is there any way to capture an image using the camera, programatically, without the user pressing a button?

I wish to take a picture on a timer, and process the image at regular intervals, but cannot find an开发者_运维问答ything.

Any help would be appreciated,

Cheers.


There's no way for 3rd party apps to take a picture without the users interaction in this v1 release of the 3rd Party SDK. AR capability is on the radar for the platform team though, so watch this space.

Picture taking capability is currently provided through CameraCaptureTask.


FYI: In Windows Phone OS 7.1 (a.k.a. "Mango"), you can now programmatically capture an image from the camera using the PhotoCamera class. Fire-off a camera capture using the CaptureImage method. When the capture is available, you can access the image (and a thumbnail) from the arguments in the eventhandlers for CaptureImageAvailable and CaptureThumbnailAvailable.

This process is fully described in the following topic:

How to: Create a Base Camera Application for Windows Phone

In that sample, a button is used to trigger the call to CaptureImage, but in a real-world application a timer, like you suggested, would be much more appropriate. (we recommend using the hardware button for user-triggered photos, rather than a UI button. That is described here: How to: Access the Hardware Camera Shutter Button).

Here's the method that actually programmatically triggers the image capture, where cam is the PhotoCamera object:

private void ShutterButton_Click(object sender, RoutedEventArgs e)
{
    // Capture a still image. Events are fired as the thumbnail 
    // and full resolution images become available.
    try
    {
        cam.CaptureImage();
    }
    catch (Exception ex)
    {
        this.Dispatcher.BeginInvoke(delegate()
        {
            // Cannot capture an image until the previous capture has completed.
            txtDebug.Text = ex.Message;
        });
    }
}

Note: PhotoCamera will throw an exception if you try to capture when another capture is in progress. You probably wouldn't have this problem with a timer-based app, but that is why the try/catch is used here. Also, BeginInvoke is used to access the UI thread and display the message in a textBlock on the corresponding page.

Hope that helps. Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜