當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。