当前位置: 首页>>代码示例>>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;未经允许,请勿转载。