如何在 windows phone/desktop 上使用相机拍摄 picture/photo

How do I take a picture/photo using a camera on windows phone/desktop

我想制作一个应用程序来拍摄可以保存到文件或显示到屏幕上的照片,但找不到从哪里开始。

如果您的目标是 phone 或桌面,我建议您创建一个 c# Universal Windows App

要拍照你可以使用LowLagPhotoCapture to get a SoftwareBitmap

    public async Task<SoftwareBitmap> takePhotoToSoftwareBitmap()
    {
        //initialize mediacapture with default camera
        var mc = new MediaCapture();
        await mc.InitializeAsync();

        //create low lag capture and take photo
        var lowLagCapture = await mc.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
        var photo = await lowLagCapture.CaptureAsync();

        //convert to displayable format
        SoftwareBitmap displayableImage;
        using (var frame = photo.Frame)
        {
            displayableImage = SoftwareBitmap.Convert(photo.Frame.SoftwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
        }

        return displayableImage;
    }

要了解如何使用 (Save/Display/Edit) SoftwareBitmap,请参阅 Imaging How-To

有关更多 Windows 相机文档,请参阅 GitHub Samples or MediaCapture How-To