本文整理汇总了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;
}
示例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;
}
示例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;
}