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


C# IStorageFile.OpenAsync方法代码示例

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


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

示例1: SaveToFile

        public static async Task SaveToFile(
            this WriteableBitmap writeableBitmap,
            IStorageFile outputFile,
            Guid encoderId)
        {
            try
            {
                Stream stream = writeableBitmap.PixelBuffer.AsStream();
                byte[] pixels = new byte[(uint)stream.Length];
                await stream.ReadAsync(pixels, 0, pixels.Length);

                using (var writeStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(encoderId, writeStream);
                    encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Premultiplied,
                        (uint)writeableBitmap.PixelWidth,
                        (uint)writeableBitmap.PixelHeight,
                        96,
                        96,
                        pixels);
                    await encoder.FlushAsync();

                    using (var outputStream = writeStream.GetOutputStreamAt(0))
                    {
                        await outputStream.FlushAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
        }
开发者ID:liquidboy,项目名称:X,代码行数:35,代码来源:WriteableBitmapExtensions.cs

示例2: Hash

        public static async Task<string> Hash(IStorageFile file)
        {
            string res = string.Empty;

            using(var streamReader = await file.OpenAsync(FileAccessMode.Read))
            {
                var alg = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
                var algHash = alg.CreateHash();

                using(BinaryReader reader = new BinaryReader(streamReader.AsStream(), Encoding.UTF8))
                {
                    byte[] chunk;

                    chunk = reader.ReadBytes(CHUNK_SIZE);
                    while(chunk.Length > 0)
                    {
                        algHash.Append(CryptographicBuffer.CreateFromByteArray(chunk));
                        chunk = reader.ReadBytes(CHUNK_SIZE);
                    }
                }

                res = CryptographicBuffer.EncodeToHexString(algHash.GetValueAndReset());
                return res;
            }
        }
开发者ID:Lukasss93,项目名称:AuraRT,代码行数:25,代码来源:MD5.cs

示例3: CreateAsync

        public static async Task<FlacMediaSourceAdapter> CreateAsync(IStorageFile file)
        {
            var fileStream = await file.OpenAsync(FileAccessMode.Read);
            var adapter = new FlacMediaSourceAdapter();
            adapter.Initialize(fileStream);

            return adapter;
        }
开发者ID:jayharry28,项目名称:Audiotica,代码行数:8,代码来源:FlacMediaSourceAdapter.cs

示例4: Save_as

 public async void Save_as(IStorageFile file, Excuse excuseToWrite)
 {
     using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
         using(Stream outputStream = stream.AsStreamForWrite())
     {
         DataContractSerializer serializer = new DataContractSerializer(typeof(Excuse));
         serializer.WriteObject(outputStream, excuseToWrite);
     }
     OnPropertyChanged("excuseToWrite");
 }
开发者ID:husaynable,项目名称:excuse_manager,代码行数:10,代码来源:Excuse.cs

示例5: GetImageFromFileAsync

        public static async Task<BitmapImage> GetImageFromFileAsync(IStorageFile file)
        {
            IRandomAccessStream fileStream =
                              await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            // Set the image source to the selected bitmap.
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.SetSource(fileStream);

            return bitmapImage;
        }
开发者ID:robertiagar,项目名称:Pixelator,代码行数:11,代码来源:PixelatorBitmap.cs

示例6: OpenFile

 public async Task<Excuse> OpenFile(IStorageFile file, Excuse excuseToRead)
 {
     using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
         using(Stream inputStream = stream.AsStreamForRead())
     {
         DataContractSerializer serializer = new DataContractSerializer(typeof(Excuse));
         excuseToRead = serializer.ReadObject(inputStream) as Excuse;
     }
     return excuseToRead;
     
 }
开发者ID:husaynable,项目名称:excuse_manager,代码行数:11,代码来源:Excuse.cs

示例7: ReadFromFile

        public static async Task<byte[]> ReadFromFile(IStorageFile file)
        {
            var stream = await file.OpenAsync(FileAccessMode.Read);
            var reader = new DataReader(stream.GetInputStreamAt(0));

            var streamSize = (uint) stream.Size;
            await reader.LoadAsync(streamSize);
            var buffer = new byte[streamSize];
            reader.ReadBytes(buffer);
            return buffer;
        }
开发者ID:jbouwens,项目名称:Put.io.Wp,代码行数:11,代码来源:FileExtensions.cs

示例8: LoadPwDatabase

        public async Task LoadPwDatabase(IStorageFile pwDatabaseFile, IList<IUserKey> userKeys, IProgress<double> percentComplete)
        {
            StorageFile = pwDatabaseFile;
            var factory = new KdbReaderFactory(_encryptionEngine,
                      _keyTransformer,
                      _hasher,
                      _gzipStreamFactory);

            var file = await pwDatabaseFile.OpenAsync(FileAccessMode.Read);

            Stream kdbDataReader = file.AsStream();

            this.PwDatabase = await factory.LoadAsync(kdbDataReader, userKeys, percentComplete);
        }
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:14,代码来源:PwDatabaseDataSource.cs

示例9: ReadGuyAsync

        public async void ReadGuyAsync()
        {
            if (String.IsNullOrEmpty(Path))
                return;
            latestGuyFile = await StorageFile.GetFileFromPathAsync(Path);

            using (IRandomAccessStream stream =
                        await latestGuyFile.OpenAsync(FileAccessMode.Read))
            using (Stream inputStream = stream.AsStreamForRead())
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(Guy));
                NewGuy = serializer.ReadObject(inputStream) as Guy;
            }
            OnPropertyChanged("NewGuy");
            OnPropertyChanged("LatestGuyFile");
        }
开发者ID:HeberAlvarez,项目名称:HeadFirst,代码行数:16,代码来源:GuyManager.cs

示例10: ReadTextAsync

        /// <summary>
        /// Reads the contents of the specified file and returns text.
        /// </summary>
        /// <param name="file">The file to read.</param>
        public static async Task<string> ReadTextAsync(IStorageFile file)
        {
            using (var fs = await file.OpenAsync(FileAccessMode.Read))
            {
                using (var inStream = fs.GetInputStreamAt(0))
                {
                    using (var reader = new DataReader(inStream))
                    {
                        await reader.LoadAsync((uint)fs.Size);
                        string data = reader.ReadString((uint)fs.Size);
                        reader.DetachStream();

                        return data;
                    }
                }
            }
        }
开发者ID:Syn-McJ,项目名称:PlugToolkit,代码行数:21,代码来源:FileIO.cs

示例11: SaveToStorageFile

        /// <summary>
        /// Saves the given <see cref="WriteableBitmap" /> to a specified storage file.
        /// </summary>
        /// <param name="writeableBitmap">The writeable bitmap.</param>
        /// <param name="storageFile">The storage file.</param>
        public static async Task SaveToStorageFile(this WriteableBitmap writeableBitmap, IStorageFile storageFile)
        {
            using (var writestream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, writestream);

                using (var pixelStream = writeableBitmap.PixelBuffer.AsStream())
                {
                    var pixels = new byte[pixelStream.Length];
                    await pixelStream.ReadAsync(pixels, 0, pixels.Length);

                    encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
                        (uint)writeableBitmap.PixelWidth, (uint)writeableBitmap.PixelHeight, 96.0, 96.0, pixels);

                    await encoder.FlushAsync();
                }
            }
        }
开发者ID:Microsoft,项目名称:Appsample-Photosharing,代码行数:23,代码来源:WriteableBitmapExtensions.cs

示例12: WriteTextAsync

        /// <summary>
        /// Writes text to the specified file.
        /// </summary>
        /// <param name="file">The file that the text is written to.</param>
        /// <param name="contents">The text to write.</param>
        public static async Task WriteTextAsync(IStorageFile file, string contents)
        {
            using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                using (var outStream = fs.GetOutputStreamAt(0))
                {
                    using (var dataWriter = new DataWriter(outStream))
                    {
                        if (contents != null)
                        {
                            dataWriter.WriteString(contents);
                        }

                        await dataWriter.StoreAsync();
                        dataWriter.DetachStream();
                    }

                    await outStream.FlushAsync();
                }
            }
        }
开发者ID:Syn-McJ,项目名称:PlugToolkit,代码行数:26,代码来源:FileIO.cs

示例13: ResizeAndSaveAs

        internal static async Task ResizeAndSaveAs(IStorageFile source, IStorageFile destination, 
            int targetDimension)
        {
            // open the file...
            using(var sourceStream = await source.OpenReadAsync())
            {
                // step one, get a decoder...
                var decoder = await BitmapDecoder.CreateAsync(sourceStream);

                // step two, create somewhere to put it...
                using(var destinationStream = await destination.OpenAsync(FileAccessMode.ReadWrite))
                {
                    // step three, create an encoder...
                    var encoder = await BitmapEncoder.CreateForTranscodingAsync(destinationStream, decoder);

                    // how big is it?
                    uint width = decoder.PixelWidth;
                    uint height = decoder.PixelHeight;
                    decimal ratio = (decimal)width / (decimal)height;

                    // orientation?
                    bool portrait = width < height;

                    // step four, configure it...
                    if (portrait)
                    {
                        encoder.BitmapTransform.ScaledHeight = (uint)targetDimension;
                        encoder.BitmapTransform.ScaledWidth = (uint)((decimal)targetDimension * ratio);
                    }
                    else
                    {
                        encoder.BitmapTransform.ScaledWidth = (uint)targetDimension;
                        encoder.BitmapTransform.ScaledHeight = (uint)((decimal)targetDimension / ratio);
                    }

                    // step five, write it...
                    await encoder.FlushAsync();
                }
            }
        }
开发者ID:mbrit,项目名称:ProgrammingMetroStyle,代码行数:40,代码来源:ImageHelper.cs

示例14: WriteGuyAsync

        public async void WriteGuyAsync(Guy guyToWrite)
        {
            IStorageFolder guysFolder =
                await KnownFolders.DocumentsLibrary.CreateFolderAsync("Guys",
                                                    CreationCollisionOption.OpenIfExists);
            latestGuyFile =
                    await guysFolder.CreateFileAsync(guyToWrite.Name + ".xml",
                                            CreationCollisionOption.ReplaceExisting);

            using (IRandomAccessStream stream =
                                await latestGuyFile.OpenAsync(FileAccessMode.ReadWrite))
            using (Stream outputStream = stream.AsStreamForWrite())
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(Guy));
                serializer.WriteObject(outputStream, guyToWrite);
            }

            Path = latestGuyFile.Path;

            OnPropertyChanged("Path");
            OnPropertyChanged("LatestGuyFile");
        }
开发者ID:HeberAlvarez,项目名称:HeadFirst,代码行数:22,代码来源:GuyManager.cs

示例15: LoadImage

        private static async Task<BitmapImage> LoadImage(IStorageFile file)
        {
            var bitmapImage = new BitmapImage();
            var stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);

            bitmapImage.SetSource(stream);

            return bitmapImage;
        }
开发者ID:msk-one,项目名称:CollectorUWP,代码行数:9,代码来源:AddDebt.xaml.cs


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