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


C# StorageFile.OpenAsync方法代码示例

本文整理汇总了C#中Windows.Storage.StorageFile.OpenAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.OpenAsync方法的具体用法?C# StorageFile.OpenAsync怎么用?C# StorageFile.OpenAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.StorageFile的用法示例。


在下文中一共展示了StorageFile.OpenAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveToFile

        private async Task<Uri> SaveToFile(StorageFile file)
        {
            Uri uri = null;

            if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                try
                {
                    using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);
                        uri = new Uri("ms-appdata:///local/" + file.Name);
                    }
                }
                catch (Exception ex)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                }
            }


            return uri;
        }
开发者ID:Ronacs,项目名称:WinDevCamp,代码行数:26,代码来源:InkNotesControl.xaml.cs

示例2: OnDeferredImageRequestedHandler

        private async void OnDeferredImageRequestedHandler(DataProviderRequest providerRequest, StorageFile imageFile)
        {
            // In this delegate we provide updated Bitmap data using delayed rendering.

            if (imageFile != null)
            {
                // If the delegate is calling any asynchronous operations it needs to acquire the deferral first. This lets the
                // system know that you are performing some operations that might take a little longer and that the call to
                // SetData could happen after the delegate returns. Once you acquired the deferral object you must call Complete
                // on it after your final call to SetData.
                DataProviderDeferral deferral = providerRequest.GetDeferral();
                InMemoryRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();

                // Make sure to always call Complete when done with the deferral.
                try
                {
                    // Decode the image and re-encode it at 50% width and height.
                    IRandomAccessStream imageStream = await imageFile.OpenAsync(FileAccessMode.Read);
                    BitmapDecoder imageDecoder = await BitmapDecoder.CreateAsync(imageStream);
                    BitmapEncoder imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
                    imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelWidth * 0.5);
                    imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
                    await imageEncoder.FlushAsync();

                    providerRequest.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));
                }
                finally
                {
                    deferral.Complete();
                }
            }
        }
开发者ID:oldnewthing,项目名称:old-Windows8-samples,代码行数:32,代码来源:ShareDelayRenderedFiles.xaml.cs

示例3: SaveToFileAsync

        async Task<RenderTargetBitmap> SaveToFileAsync(FrameworkElement uielement, StorageFile file)
        {
            if (file != null)
            {
                CachedFileManager.DeferUpdates(file);

                Guid encoderId = GetBitmapEncoder(file.FileType);

                try
                {
                    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        return await CaptureToStreamAsync(uielement, stream, encoderId);
                    }
                }
                catch (Exception ex)
                {
                    DisplayMessage(ex.Message);
                }

                var status = await CachedFileManager.CompleteUpdatesAsync(file);
            }

            return null;
        }
开发者ID:ndm4766,项目名称:SmartStroke,代码行数:25,代码来源:ScreenExporter.cs

示例4: GetDominantColorFromFile

        public static async Task<Color> GetDominantColorFromFile(StorageFile file)
        {
            //get the file

            using (var stream = await file.OpenAsync(FileAccessMode.Read))
            {
                //Create a decoder for the image
                var decoder = await BitmapDecoder.CreateAsync(stream);

                //Create a transform to get a 1x1 image
                var myTransform = new BitmapTransform { ScaledHeight = 1, ScaledWidth = 1 };

                //Get the pixel provider
                var pixels = await decoder.GetPixelDataAsync(
                    BitmapPixelFormat.Rgba8,
                    BitmapAlphaMode.Ignore,
                    myTransform,
                    ExifOrientationMode.IgnoreExifOrientation,
                    ColorManagementMode.DoNotColorManage);

                //Get the bytes of the 1x1 scaled image
                var bytes = pixels.DetachPixelData();

                //read the color 
                var myDominantColor = Color.FromArgb(255, bytes[0], bytes[1], bytes[2]);

                return myDominantColor;
            }
        }
开发者ID:HimanshPal,项目名称:Naylah.Toolkit.UWP,代码行数:29,代码来源:ColorHelper.cs

示例5: LoadImage

 private async Task<BitmapImage> LoadImage(StorageFile file)
 {
     var image  = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
     image.SetSource(stream);
     return image;
 }
开发者ID:ma1982en,项目名称:curly-octo-pancake,代码行数:7,代码来源:ChoosingViewModel.cs

示例6: Capture_Click

        /// <summary>
        /// Triggered when the Capture Photo button is clicked by the user
        /// </summary>
        private async void Capture_Click(object sender, RoutedEventArgs e)
        {
            // Hide the capture photo button
            CaptureButton.Visibility = Visibility.Collapsed;

            // Capture current frame from webcam, store it in temporary storage and set the source of a BitmapImage to said photo
            currentIdPhotoFile = await webcam.CapturePhoto();
            var photoStream = await currentIdPhotoFile.OpenAsync(FileAccessMode.ReadWrite);
            BitmapImage idPhotoImage = new BitmapImage();
            await idPhotoImage.SetSourceAsync(photoStream);
            

            // Set the soruce of the photo control the new BitmapImage and make the photo control visible
            IdPhotoControl.Source = idPhotoImage;
            IdPhotoControl.Visibility = Visibility.Visible;

            // Collapse the webcam feed or disabled feed grid. Make the enter user name grid visible.
            WebcamFeed.Visibility = Visibility.Collapsed;
            DisabledFeedGrid.Visibility = Visibility.Collapsed;

            UserNameGrid.Visibility = Visibility.Visible;
            

            // Dispose photo stream
            photoStream.Dispose();
        }
开发者ID:vishalishere,项目名称:Facial-Recognition-Door,代码行数:29,代码来源:NewUserPage.xaml.cs

示例7: GetImageAsync

 public async static Task<BitmapImage> GetImageAsync(StorageFile storageFile)
 {
     BitmapImage bitmapImage = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read);
     bitmapImage.SetSource(stream);
     return bitmapImage;
 }
开发者ID:Ivalaostia,项目名称:UniversalHelpers,代码行数:7,代码来源:Utilities.cs

示例8: DisplayImageFileAsync

 /// <summary>
 /// This function would display the Image 
 /// </summary>
 public async Task DisplayImageFileAsync(StorageFile file)
 {            
     // Display the image in the UI.
     BitmapImage src = new BitmapImage();
     src.SetSource(await file.OpenAsync(FileAccessMode.Read));
     Image1.Source = src;           
 }
开发者ID:oldnewthing,项目名称:old-Windows8-samples,代码行数:10,代码来源:1_RenderPage.xaml.cs

示例9: WriteSurveyPhotoMetaData

        /// <summary>
        /// Write the location metadata to the image file
        /// </summary>
        public async static Task WriteSurveyPhotoMetaData(StorageFile file, Geoposition pos, string surveyId = "")
        {
            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                var decoder = await BitmapDecoder.CreateAsync(stream);
                var encoder = await BitmapEncoder.CreateForTranscodingAsync(stream, decoder);
                
                // Write the gps data
                var propertySet = new BitmapPropertySet();
                var latitudeNumerator = new BitmapTypedValue(CoordDoubleToIntArray(pos.Coordinate.Latitude), PropertyType.Int32Array);
                var latitudeRef = new BitmapTypedValue("N", PropertyType.String);
                var longitudeNumerator = new BitmapTypedValue(CoordDoubleToIntArray(pos.Coordinate.Longitude), PropertyType.Int32Array);
                var longitudeRef = new BitmapTypedValue("W", PropertyType.String);

                propertySet.Add("System.GPS.LatitudeNumerator", latitudeNumerator);
                propertySet.Add("System.GPS.LatitudeRef", latitudeRef);
                propertySet.Add("System.GPS.LatitudeDenominator", new BitmapTypedValue(new [] { 1, 1, 10000 }, PropertyType.Int32Array));

                propertySet.Add("System.GPS.LongitudeNumerator", longitudeNumerator);
                propertySet.Add("System.GPS.LongitudeRef", longitudeRef);
                propertySet.Add("System.GPS.LongitudeDenominator", new BitmapTypedValue(new[] { 1, 1, 10000 }, PropertyType.Int32Array));

                // Write the surveyId data
                if (!string.IsNullOrEmpty(surveyId))
                {
                    var surveyIdTyped = new BitmapTypedValue(surveyId, Windows.Foundation.PropertyType.String);
                    propertySet.Add("System.Comment", surveyIdTyped);
                }

                await encoder.BitmapProperties.SetPropertiesAsync(propertySet);
                await encoder.FlushAsync();
            }
        }
开发者ID:yuqiqian,项目名称:Copacescc,代码行数:36,代码来源:ImagingHelper.cs

示例10: Save

        /// <summary>
        /// Saves the specified bitmap to the specified location.
        /// </summary>
        /// <param name="source">The source bitmap image.</param>
        /// <param name="destination">The destination storage file for the image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <param name="width">The width of the image file.</param>
        /// <param name="height">The height of the image file.</param>
        /// <returns>True if the bitmap file was successfully saved. False otherwise.</returns>
        public async Task<bool> Save(WriteableBitmap source, StorageFile destination, int width, int height)
        {
            if (source == null || destination == null) return false;

            try
            {
                Guid encoderID = GetEncoderId(destination);

                using (IRandomAccessStream stream = await destination.OpenAsync(FileAccessMode.ReadWrite))
                {
                    Stream pixelStream = source.PixelBuffer.AsStream();
                    byte[] pixels = new byte[pixelStream.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);

                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(encoderID, stream);
                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)source.PixelWidth, (uint)source.PixelHeight, Constants.DPI, Constants.DPI, pixels);

                    if (source.PixelWidth != width || source.PixelHeight != height)
                    {
                        encoder.BitmapTransform.ScaledWidth = (uint)width;
                        encoder.BitmapTransform.ScaledHeight = (uint)height;
                    }

                    await encoder.FlushAsync();
                }

                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return false;
        }
开发者ID:L-SEG,项目名称:Vitruvius,代码行数:43,代码来源:BitmapCapture.cs

示例11: seleccionarImagen

        private async void seleccionarImagen(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".png");
            file = await picker.PickSingleFileAsync();

            BitmapImage image = new BitmapImage();
            try
            {
                using (var stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    await image.SetSourceAsync(stream);
                }
                ImageBrush brush = new ImageBrush();
                brush.Stretch = Stretch.UniformToFill;
                brush.ImageSource = image;
                imagen.Fill = brush;
            }
            catch (Exception exception)
            {

            }
            
        }
开发者ID:wgcarvajal,项目名称:HuellitaW10,代码行数:25,代码来源:AgregarFotoMascotaPage.xaml.cs

示例12: GameViewModel

        protected GameViewModel()
            : base()
        {
           CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                MediaPlayer = new MediaElement();
            });

            lock (locker)
            {
                if (StopwatchFile == null || AlarmFile == null)
                {
                    LoadFileTask = Task.Run(async () =>
                {
                    StorageFolder folder = await (await Package.Current.InstalledLocation.GetFolderAsync("Assets")).GetFolderAsync("Sounds");
                    StopwatchFile = await folder.GetFileAsync("Stopwatch.wav");
                    AlarmFile = await folder.GetFileAsync("Alarm.wav");
                    CheerFile = await folder.GetFileAsync("Cheer.wav");
                    AwwFile = await folder.GetFileAsync("Aww.wav");
                    VictoryFile = await folder.GetFileAsync("Victory.wav");

                    (await StopwatchFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(StopwatchStream);
                    (await AlarmFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(AlarmStream);
                    (await CheerFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(CheerStream);
                    (await AwwFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(AwwStream);
                    (await VictoryFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(VictoryStream);

                });
                }
            }
        }
开发者ID:Speedydown,项目名称:Thirty_Seconds_WP,代码行数:31,代码来源:GameViewModel.cs

示例13: EncodeFromStorageFile

 public static async Task<string> EncodeFromStorageFile(StorageFile bitmap)
 {
     var stream = await bitmap.OpenAsync(Windows.Storage.FileAccessMode.Read);
     var decoder = await BitmapDecoder.CreateAsync(stream);
     var pixels = await decoder.GetPixelDataAsync();
     var bytes = pixels.DetachPixelData();
     return await EncodeFromByte(bytes, (uint)decoder.PixelWidth, (uint)decoder.PixelHeight, decoder.DpiX, decoder.DpiY);
 }
开发者ID:Lukasss93,项目名称:AuraRT,代码行数:8,代码来源:Base64.cs

示例14: ToBase64

 public static async Task<string> ToBase64(StorageFile bitmap)
 {
     var stream = await bitmap.OpenAsync(FileAccessMode.Read);
     var decoder = await BitmapDecoder.CreateAsync(stream);
     var pixels = await decoder.GetPixelDataAsync();
     var bytes = pixels.DetachPixelData();
     return await ToBase64(bytes, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY);
 }
开发者ID:msk-one,项目名称:CollectorUWP,代码行数:8,代码来源:Base64Converter.cs

示例15: GetImage

        static async public Task<BitmapImage> GetImage(StorageFile file)
        {
            IRandomAccessStream photoStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            BitmapImage bmpimg = new BitmapImage();
            bmpimg.SetSource(photoStream);

            return bmpimg;
        }
开发者ID:karlsburg,项目名称:ReasonCam,代码行数:8,代码来源:ImageController.cs


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