本文整理汇总了C#中Windows.Storage.StorageFile.CopyAndReplaceAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.CopyAndReplaceAsync方法的具体用法?C# StorageFile.CopyAndReplaceAsync怎么用?C# StorageFile.CopyAndReplaceAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFile
的用法示例。
在下文中一共展示了StorageFile.CopyAndReplaceAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResizeImageUniformAsync
public static async Task ResizeImageUniformAsync(StorageFile sourceFile, StorageFile targetFile, int maxWidth = Int32.MaxValue, int maxHeight = Int32.MaxValue)
{
using (var stream = await sourceFile.OpenReadAsync())
{
var decoder = await BitmapDecoder.CreateAsync(stream);
if (IsGifImage(decoder))
{
await sourceFile.CopyAndReplaceAsync(targetFile);
return;
}
maxWidth = Math.Min(maxWidth, (int)decoder.OrientedPixelWidth);
maxHeight = Math.Min(maxHeight, (int)decoder.OrientedPixelHeight);
var imageSize = new Size(decoder.OrientedPixelWidth, decoder.OrientedPixelHeight);
var finalSize = imageSize.ToUniform(new Size(maxWidth, maxHeight));
if (finalSize.Width == decoder.OrientedPixelWidth && finalSize.Height == decoder.OrientedPixelHeight)
{
await sourceFile.CopyAndReplaceAsync(targetFile);
return;
}
await ResizeImageAsync(decoder, targetFile, finalSize);
}
}
示例2: CreateCopyOfSelectedImage
public static async Task<StorageFile> CreateCopyOfSelectedImage(StorageFile file)
{
var newSourceFileName = string.Format(@"{0}.jpg", Guid.NewGuid());
var newSourceFile =
await
ApplicationData.Current.TemporaryFolder.CreateFileAsync(newSourceFileName,
CreationCollisionOption.ReplaceExisting);
await file.CopyAndReplaceAsync(newSourceFile);
return newSourceFile;
}
示例3: CopyImageToLocalFolderAsync
private async Task CopyImageToLocalFolderAsync(StorageFile file)
{
OutputTextBlock.Text = string.Empty;
if (file != null)
{
StorageFile newFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(file.Name, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
await file.CopyAndReplaceAsync(newFile);
this.imageRelativePath = newFile.Path.Substring(newFile.Path.LastIndexOf("\\") + 1);
rootPage.NotifyUser("Image copied to application data local storage: " + newFile.Path, NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser("File was not copied due to error or cancelled by user.", NotifyType.ErrorMessage);
}
}
示例4: Button_Click
/// <summary>
/// Permissions needed: Webcam, Microphone, PicturesLibrary, VideosLibrary
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Button_Click(object sender, RoutedEventArgs e)
{
// Capture photo
var camera = new CameraCaptureUI();
image = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
DisplayNotification("Photo captured", "Hey good lookin'");
// Save image to Pictures Library
var saveImageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("test.jpg", CreationCollisionOption.ReplaceExisting);
await image.CopyAndReplaceAsync(saveImageFile);
DisplayNotification("Photo saved", "test.jpg");
}
示例5: SetNewImage
public async void SetNewImage(StorageFile originalFile)
{
if (originalFile != null)
{
var newFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(originalFile.Name, CreationCollisionOption.GenerateUniqueName);
await originalFile.CopyAndReplaceAsync(newFile);
Image = newFile.Path;
}
}
示例6: file2SoftwareBitmapSource
private async void file2SoftwareBitmapSource(StorageFile file, int index = 0, bool isAddImage = false)
{
if (!isAddImage)
{
IStorageFolder applicationFolder = ApplicationData.Current.TemporaryFolder;
await file.CopyAndReplaceAsync(await applicationFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting));
}
SoftwareBitmapSource source = new SoftwareBitmapSource();
SoftwareBitmap sb = null;
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
sb = softwareBitmap;
}
await source.SetBitmapAsync(sb);
imageList.Insert(index, new CommunityImageList { imgUri = source, imgName = file.Name, imgPath = file.Path, imgAppPath = "ms-appdata:///Temp/" + file.Name });
}
示例7: ImportTimetable
public static async Task ImportTimetable(StorageFile file)
{
var fileName = await ReserveNewTimetableFilename();
var destinationFile = await (await GetTimetableDirectory()).GetFileAsync(fileName);
try
{
await file.CopyAndReplaceAsync(destinationFile);
Timetable.ParseXml(await FileIO.ReadTextAsync(destinationFile), fileName, Strings.TimetableNewName);
return;
}
catch { }
await destinationFile.DeleteAsync();
await new MessageDialog(Strings.TimetableIOImportError, Strings.MessageBoxWarningCaption).ShowAsync();
}