コード例 #1
0
        /// <summary>
        /// 停止预览
        /// </summary>
        public static async Task StopPreview()
        {
            try
            {
                if (CameraPreviewSizeList != null)
                {
                    CameraPreviewSizeList.Clear();
                }
                CameraPreviewSizeList = null;
                if (CameraPhotoSizeList != null)
                {
                    CameraPhotoSizeList.Clear();
                }
                await CloseLowLagPhoto();

                CameraPhotoSizeList        = null;
                IsSupportROI               = false;
                IsSupportContinuousCapture = false;
                IsSupportHWZoom            = false;
                if (MainCamera != null)
                {
                    try
                    {
                        await MainCamera.StopPreviewAsync();
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        MainCamera.Dispose();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                MainCamera       = null;
                CurrentCamDevice = null;
                FailedIndex      = 1;
                IsCanUseCamera   = false;
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
0
        /// <summary>
        /// 获得照片分辨率
        /// </summary>
        private static void GetPhotoSize()
        {
            if (PhotoSource == PhotoCaptureSource.VideoPreview)
            {
                return;
            }
            var photoSizeList = MainCamera.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
            var imageSizeList = new List <ImageEncodingProperties>();
            var videoSizeList = new List <VideoEncodingProperties>();

            foreach (var item in photoSizeList)
            {
                if (item.Type == "Image")
                {
                    var imageSize = (ImageEncodingProperties)item;
                    if (imageSize.Width < AppDefaultHelper.CAMERA_VGA_WIDTH || imageSize.Height < AppDefaultHelper.CAMERA_VGA_HEIGHT)
                    {
                        continue;
                    }
                    imageSizeList.Add(imageSize);
                }
                else
                {
                    var videoSize = (VideoEncodingProperties)item;
                    if (videoSize.Width < AppDefaultHelper.CAMERA_VGA_WIDTH || videoSize.Height < AppDefaultHelper.CAMERA_VGA_HEIGHT)
                    {
                        continue;
                    }
                    var oldItem = videoSizeList.FirstOrDefault(li => li.Width == videoSize.Width && li.Height == videoSize.Height);
                    if (oldItem == null)
                    {
                        videoSizeList.Add(videoSize);
                    }
                }
            }
            if (CameraPhotoSizeList == null)
            {
                CameraPhotoSizeList = new List <CameraSizeInfo>();
            }
            else
            {
                CameraPhotoSizeList.Clear();
            }
            if (imageSizeList.Count > 0)
            {
                imageSizeList.Sort((Comparison <ImageEncodingProperties>)((p1, p2) =>
                {
                    if (p1 == null || p2 == null)
                    {
                        return(0);
                    }
                    uint pixels0 = p1.Height * p1.Width;
                    uint pixels1 = p2.Height * p2.Width;
                    if (pixels0 > pixels1)
                    {
                        return(1);
                    }
                    return((int)pixels0 == (int)pixels1 ? 0 : -1);
                }));
                foreach (var item in imageSizeList)
                {
                    CameraPhotoSizeList.Add(new CameraSizeInfo(item, item.Width, item.Height));
                }
                IsPhotoFromImagePropStream = true;
            }
            else if (videoSizeList.Count > 0)
            {
                videoSizeList.Sort((Comparison <VideoEncodingProperties>)((p1, p2) =>
                {
                    if (p1 == null || p2 == null)
                    {
                        return(0);
                    }
                    uint pixels0 = p1.Height * p1.Width;
                    uint pixels1 = p2.Height * p2.Width;
                    if (pixels0 > pixels1)
                    {
                        return(1);
                    }
                    return((int)pixels0 == (int)pixels1 ? 0 : -1);
                }));
                foreach (var item in videoSizeList)
                {
                    CameraPhotoSizeList.Add(new CameraSizeInfo(item, item.Width, item.Height));
                }
                IsPhotoFromImagePropStream = false;
            }
        }