當前位置: 首頁>>代碼示例>>C#>>正文


C# StorageFolder.CreateTempFileNameAsync方法代碼示例

本文整理匯總了C#中Windows.Storage.StorageFolder.CreateTempFileNameAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# StorageFolder.CreateTempFileNameAsync方法的具體用法?C# StorageFolder.CreateTempFileNameAsync怎麽用?C# StorageFolder.CreateTempFileNameAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Storage.StorageFolder的用法示例。


在下文中一共展示了StorageFolder.CreateTempFileNameAsync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CapturePhotoToStorageFileAsync

        /// <summary>
        /// Captures the photo to storage file asynchronously.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="defaultExtension">The default extension.</param>
        /// <returns></returns>
        public async Task<StorageFile> CapturePhotoToStorageFileAsync(StorageFolder folder = null, string fileName = null, string defaultExtension = ".jpg")
        {
            if (_countdownControl != null &&
                this.PhotoCaptureCountdownSeconds > 0)
            {
#pragma warning disable 4014
                _countdownControl.FadeInCustom();
                await _countdownControl.StartCountdownAsync(this.PhotoCaptureCountdownSeconds);
                _countdownControl.FadeOutCustom();
#pragma warning restore 4014
            }

            if (_flashAnimation != null)
                _flashAnimation.Begin();

            if (folder == null)
            {
                folder = KnownFolders.PicturesLibrary;
            }

            if (fileName == null)
            {
                fileName = await folder.CreateTempFileNameAsync(defaultExtension);
            }

            var photoFile = await folder.CreateFileAsync(
                fileName,
                CreationCollisionOption.FailIfExists);

            ImageEncodingProperties imageEncodingProperties;

            switch (Path.GetExtension(fileName))
            {
                case ".png":
                    imageEncodingProperties = ImageEncodingProperties.CreatePng();
                    break;
                default:
                    imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
                    break;
            }

            try
            {
                await MediaCapture.CapturePhotoToStorageFileAsync(imageEncodingProperties, photoFile);
            }
            catch
            {
                OnCameraFailed(null, null);
                return null;
            }

            //using (var stream = await photoFile.OpenStreamForWriteAsync())
            //using (var yas = stream.AsRandomAccessStream())
            //{
            //    try
            //    {
            //        await MediaCapture.CapturePhotoToStreamAsync(imageEncodingProperties, yas);
            //    }
            //    catch
            //    {
            //        OnCameraFailed(null, null);
            //        return null;
            //    }
            //}

            return photoFile;
        }
開發者ID:kasparov,項目名稱:StoryTeller,代碼行數:74,代碼來源:CameraCaptureControl.cs

示例2: StartVideoCaptureAsync

        /// <summary>
        /// Starts the video capture asynchronously.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException"></exception>
        public async Task<StorageFile> StartVideoCaptureAsync(StorageFolder folder = null, string fileName = null)
        {
            if (_internalState == CameraCaptureControlStates.Recording)
            {
                // Note: Already recording - ignoring the folder and filename and returning result of previous request.
                await _recordingTaskSource.Task;
                return _videoFile;
            }

            if (_internalState != CameraCaptureControlStates.Shown)
            {
                var result = await ShowAsync();

                if (!result.Success)
                {
                    //TODO: Add error handling here.

                    return null;
                }
            }

            _internalState = CameraCaptureControlStates.Recording;
            _recordingTaskSource = new TaskCompletionSource<bool>(false);

            if (MediaCapture == null)
            {
                throw new InvalidOperationException();
            }

            if (folder == null)
            {
                folder = KnownFolders.VideosLibrary;
            }

            if (fileName == null)
            {
                fileName = await folder.CreateTempFileNameAsync(".mp4");
            }

            _videoFile = await folder.CreateFileAsync(
                fileName,
                CreationCollisionOption.FailIfExists);

            if (_recordingIndicator != null)
            {
                _recordingIndicator.Visibility = Visibility.Visible;
            }

            if (_recordingAnimation != null)
            {
                _recordingAnimation.Begin();
            }

            var encodingProfile =
                Path.GetExtension(fileName).Equals(".wmv", StringComparison.OrdinalIgnoreCase) ?
                MediaEncodingProfile.CreateWmv(VideoEncodingQuality) :
                MediaEncodingProfile.CreateMp4(VideoEncodingQuality);

            await MediaCapture.StartRecordToStorageFileAsync(encodingProfile, _videoFile);
            await _recordingTaskSource.Task;
            _recordingTaskSource = null;

            if (_recordingAnimation != null)
            {
                _recordingAnimation.Stop();
            }

            if (_recordingIndicator != null)
            {
                _recordingIndicator.Visibility = Visibility.Collapsed;
            }

            _internalState = CameraCaptureControlStates.Shown;

            return _videoFile;
        }
開發者ID:kasparov,項目名稱:StoryTeller,代碼行數:83,代碼來源:CameraCaptureControl.cs

示例3: CapturePhotoToStorageFileAsync

        public async Task<StorageFile> CapturePhotoToStorageFileAsync(StorageFolder folder = null, string fileName = null)
        {
            if (_countdownControl != null &&
                this.PhotoCaptureCountdownSeconds > 0)
            {
                _countdownControl.FadeInCustom();
                await _countdownControl.StartCountdown(this.PhotoCaptureCountdownSeconds);
                _countdownControl.FadeOutCustom();
            }

            if (_flashAnimation != null)
                _flashAnimation.Begin();

            if (folder == null)
            {
                folder = KnownFolders.PicturesLibrary;
            }

            if (fileName == null)
            {
                fileName = await folder.CreateTempFileNameAsync(".png");
            }

            var photoFile = await folder.CreateFileAsync(
                fileName,
                CreationCollisionOption.FailIfExists);

            ImageEncodingProperties imageEncodingProperties;

            switch (Path.GetExtension(fileName))
            {
                case ".png":
                    imageEncodingProperties = ImageEncodingProperties.CreatePng();
                    break;
                default:
                    imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
                    break;
            }

            await _mediaCapture.CapturePhotoToStorageFileAsync(imageEncodingProperties, photoFile);

            return photoFile;
        }
開發者ID:chao-zhou,項目名稱:PomodoroTimer,代碼行數:43,代碼來源:CameraCaptureControl.cs


注:本文中的Windows.Storage.StorageFolder.CreateTempFileNameAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。