当前位置: 首页>>代码示例>>C#>>正文


C# StorageFile.CopyAndReplaceAsync方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:ridomin,项目名称:waslibs,代码行数:26,代码来源:BitmapTools.cs

示例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;
        }
开发者ID:modulexcite,项目名称:ProjectOxford,代码行数:11,代码来源:FileHelper.cs

示例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);
     }
 }
开发者ID:ckc,项目名称:WinApp,代码行数:15,代码来源:Scenario9_ImageProtocols.xaml.cs

示例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");
        }
开发者ID:sabbour,项目名称:camerademo,代码行数:19,代码来源:MainPage.xaml.cs

示例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;
     }
 }
开发者ID:acasquete,项目名称:app-to-app-uwp,代码行数:9,代码来源:MainPageViewModel.cs

示例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 });
        }
开发者ID:RedrockMobile,项目名称:CyxbsMobile_Win,代码行数:19,代码来源:CommunityAddPage.xaml.cs

示例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();
 }
开发者ID:JulianMH,项目名称:ModernTimetable,代码行数:14,代码来源:TimetableIO.cs


注:本文中的Windows.Storage.StorageFile.CopyAndReplaceAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。