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


C# IRandomAccessStream.ReadAsync方法代码示例

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


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

示例1: ReadIntoBuffer

 public static async Task<IBuffer> ReadIntoBuffer(IRandomAccessStream stream)
 {
     stream.Seek(0);
     var buffer = new Buffer((uint) stream.Size);
     await stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None);
     return buffer;
 }
开发者ID:joshholmes,项目名称:BulletTime,代码行数:7,代码来源:StorageIO.cs

示例2: InitializeAsync

 public async Task<ImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource)
 {
     byte[] bytes = new byte[streamSource.Size];
     await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token);
     var imageSource = WebpCodec.Decode(bytes);
     return imageSource;
 }
开发者ID:yyx290799684,项目名称:ImageLib.UWP,代码行数:7,代码来源:WebpDecoder.cs

示例3: Decrypt

        /// <summary>
        /// Decrypts the specified input stream.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="masterKey">The master key.</param>
        /// <param name="masterSeed">The master seed.</param>
        /// <param name="encryptionIV">The encryption initialization vector.</param>
        /// <returns>The decrypted buffer.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="input"/>, <paramref name="masterSeed"/>, <paramref name="masterKey"/>
        /// and <paramref name="encryptionIV"/> cannot be <c>null</c>.
        /// </exception>
        public static async Task<IInputStream> Decrypt(IRandomAccessStream input,
            IBuffer masterKey, IBuffer masterSeed, IBuffer encryptionIV)
        {
            if (input == null) throw new ArgumentNullException("input");
            if (masterSeed == null) throw new ArgumentNullException("masterSeed");
            if (masterKey == null) throw new ArgumentNullException("masterKey");
            if (encryptionIV == null) throw new ArgumentNullException("encryptionIV");

            var sha = HashAlgorithmProvider
                .OpenAlgorithm(HashAlgorithmNames.Sha256)
                .CreateHash();

            sha.Append(masterSeed);
            sha.Append(masterKey);

            var seed = sha.GetValueAndReset();
            var aes = SymmetricKeyAlgorithmProvider
                .OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7)
                .CreateSymmetricKey(seed);

            var buffer = WindowsRuntimeBuffer.Create(
                (int)(input.Size - input.Position));
            buffer = await input.ReadAsync(buffer, buffer.Capacity);
            buffer = CryptographicEngine.Decrypt(aes, buffer, encryptionIV);

            var stream = new InMemoryRandomAccessStream();
            await stream.WriteAsync(buffer);
            stream.Seek(0);

            return stream;
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:43,代码来源:FileFormat.cs

示例4: SaveToTemporary

 /// <summary>
 /// 
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="stream"></param>
 /// <returns></returns>
 public static async Task<StorageFile> SaveToTemporary(string fileName, IRandomAccessStream stream)
 {
     // IRandomAccessStreamのストリームを保存する
     var file = await StorageFile.CreateStreamedFileAsync(fileName,
         async writeStream =>
         {
             var imageBuffer = new byte[stream.Size];
             var ibuffer = imageBuffer.AsBuffer();
             await stream.ReadAsync(ibuffer, (uint)stream.Size, InputStreamOptions.None);
             await writeStream.WriteAsync(ibuffer);
         }, null);
     return file;
 }
开发者ID:tanaka-takayoshi,项目名称:WriteableBitmapEffector,代码行数:19,代码来源:StorageExtensions.cs

示例5: InitializeAsync

 public async Task<ExtendImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource,
      CancellationTokenSource cancellationTokenSource)
 {
     byte[] bytes = new byte[streamSource.Size];
     await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token);
     WriteableBitmap writeableBitmap = WebpCodec.Decode(bytes);
     ExtendImageSource imageSource = new ExtendImageSource();
     if (writeableBitmap != null)
     {
         imageSource.PixelWidth = writeableBitmap.PixelWidth;
         imageSource.PixelHeight = writeableBitmap.PixelHeight;
         imageSource.ImageSource = writeableBitmap;
     }
     return imageSource;
 }
开发者ID:taojunfeng,项目名称:ImageLib.UWP,代码行数:15,代码来源:WebpDecoder.cs

示例6: InitializeAsync

 public async Task<ImagePackage> InitializeAsync(CoreDispatcher dispatcher, Image image, Uri uriSource,
     IRandomAccessStream streamSource,
      CancellationTokenSource cancellationTokenSource)
 {
     byte[] bytes = new byte[streamSource.Size];
     await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token);
     int width, height;
     WriteableBitmap writeableBitmap = null;
     if (WebpCodec.GetInfo(bytes, out width, out height))
     {
         writeableBitmap = new WriteableBitmap(width, height);
         await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
          {
              var uri = image.Tag as Uri;
              if (uri == uriSource)
              {
                  image.Source = writeableBitmap;
              }
          });
         WebpCodec.Decode(writeableBitmap, bytes);
     }
     return new ImagePackage(this, writeableBitmap, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight);
 }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:23,代码来源:WebpDecoder.cs

示例7: LoadStream

        /// <summary>
        /// Set an image to this class by specifying an input stream that contains image data
        /// in one of the supported MIME types (e.g., JPEG or PNG file contents).
        /// </summary>
        /// <remarks>
        /// The stream has to contain one of the supported MIME types - e.g.,
        /// a JPEG or PNG image. The stream contents are set as the payload of this record.
        /// This method will try to find out the MIME type of the referenced
        /// stream contents automatically and adapt the type of the NDEF record accordingly.
        /// </remarks>
        /// <returns>Task to await completion of the asynchronous image loading / parsing.</returns>
        public async Task LoadStream(IRandomAccessStream imgStream)
        {
            if (imgStream == null) throw new ArgumentNullException("imgStream");
            var decoder = await BitmapDecoder.CreateAsync(imgStream);
            var fileCodecId = decoder.DecoderInformation.CodecId;

            Payload = new byte[imgStream.Size];
            await imgStream.ReadAsync(Payload.AsBuffer(), (uint)imgStream.Size, InputStreamOptions.None);
            Type = ImageMimeTypes[GetMimeTypeForBitmapDecoderId(fileCodecId)];
        }
开发者ID:SpivEgin,项目名称:ndef-nfc,代码行数:21,代码来源:NdefMimeImageRecord.cs

示例8: SaveFileAsync

        /// <summary>
        /// 指定されたフォルダーへファイルを保存する
        /// 既存の同名ファイルが存在している場合はファイルを上書きする
        /// </summary>
        /// <param name="folder">フォルダー</param>
        /// <param name="fileName">拡張子を含むファイル名</param>
        /// <param name="stream">保存するデータのストリーム</param>
        /// <returns>ファイル</returns>
        public static async Task<StorageFile> SaveFileAsync(this IStorageFolder folder, string fileName, IRandomAccessStream stream)
        {
            var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
            using (var outputStrm = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                // 書き込むファイルからデータを読み込む
                var imageBuffer = new byte[stream.Size];
                var ibuffer = imageBuffer.AsBuffer();
                stream.Seek(0);
                await stream.ReadAsync(ibuffer, (uint)stream.Size, InputStreamOptions.None);

                // データをファイルに書き出す
                await outputStrm.WriteAsync(ibuffer);
            }
            return file;
        }
开发者ID:CH3COOH,项目名称:Softbuild.Data,代码行数:24,代码来源:StorageExtensions.cs

示例9: SaveAsync

        /// <summary>
        /// ストリームを保存する
        /// </summary>
        /// <param name="file">ファイルストレージ</param>
        /// <param name="stream">保存するデータのストリーム</param>
        /// <returns>ファイル</returns>
        public static async Task<StorageFile> SaveAsync(this StorageFile file, IRandomAccessStream stream)
        {
            using (var outputStrm = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                // 書き込むファイルからデータを読み込む
                var imageBuffer = new byte[stream.Size];
                var ibuffer = imageBuffer.AsBuffer();
                stream.Seek(0);
                await stream.ReadAsync(ibuffer, (uint)stream.Size, InputStreamOptions.None);

                // データをファイルに書き出す
                await outputStrm.WriteAsync(ibuffer);
            }
            return file;
        }
开发者ID:CH3COOH,项目名称:Softbuild.Data,代码行数:21,代码来源:StorageExtensions.cs

示例10: ComputeHashAsync

        /// <summary>
        /// Computes the SHA1 hash of the given IRandomAccessStream
        /// </summary>
        /// <param name="stream">IRandomAccessStream</param>
        /// <returns>Hashed string</returns>
        private static async Task<string> ComputeHashAsync(IRandomAccessStream stream)
        {
            // Copy the stream to IBuffer
            IBuffer buffer = new Windows.Storage.Streams.Buffer((uint)stream.Size);
            buffer = await stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None);
            // Calculate the hash
            var bufferHash = AlgorithmProvider.HashData(buffer);
            // Encode to hexadecimal lowercase characters
            var hash = CryptographicBuffer.EncodeToHexString(bufferHash).ToLower();

            return hash;
        }
开发者ID:RareNCool,项目名称:CompositionProToolkit,代码行数:17,代码来源:ImageCache.cs

示例11: LoadKeyFile

        /// <summary>
        /// Loads the specified key file.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="input"/> parameter cannot be <c>null</c>.
        /// </exception>
        private static async Task<IBuffer> LoadKeyFile(IRandomAccessStream input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            var buffer = WindowsRuntimeBuffer.Create(1024);

            switch (input.Size)
            {
                case 32: // Binary key file
                    return await input.ReadAsync(buffer, 32);

                case 64: // Hex text key file
                    buffer = await input.ReadAsync(buffer, 64);
                    var hex = CryptographicBuffer.ConvertBinaryToString(
                        BinaryStringEncoding.Utf8, buffer);

                    if (IsHexString(hex))
                        return CryptographicBuffer.DecodeFromHexString(hex);
                    break;
            }

            // XML
            input.Seek(0);
            var xml = LoadXmlKeyFile(input);
            if (xml != null)
                return xml;

            // Random keyfile
            input.Seek(0);
            return await GetFileHash(input, buffer);
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:40,代码来源:PasswordData.cs

示例12: ResizeStreamAsync

        private async Task<IRandomAccessStream> ResizeStreamAsync(IRandomAccessStream stream, Size size, PhotoOrientation orientation)
        {
            var rotation = 0;

            switch (orientation)
            {
                case PhotoOrientation.Rotate180:
                    {
                        rotation = -180;
                    };
                    break;

                case PhotoOrientation.Rotate270:
                    {
                        rotation = -270;
                    };
                    break;

                case PhotoOrientation.Rotate90:
                    {
                        rotation = -90;
                    };
                    break;
            }

            using (var resizedStream = new InMemoryRandomAccessStream())
            {
                var buffer = new byte[stream.Size].AsBuffer();

                stream.Seek(0);

                await stream.ReadAsync(buffer, buffer.Length, InputStreamOptions.None);

                var resizeConfiguration = new AutoResizeConfiguration(
                    (uint)(size.Width * size.Height * 4 * 2), size,
                    new Size(0, 0), AutoResizeMode.Automatic, 0.7, ColorSpace.Yuv420);

                buffer = await JpegTools.AutoResizeAsync(buffer, resizeConfiguration);

                await resizedStream.WriteAsync(buffer);
                await resizedStream.FlushAsync();

                if (rotation != 0)
                {
                    resizedStream.Seek(0);

                    var filters = new List<IFilter>() { new RotationFilter(rotation) };

                    using (var source = new RandomAccessStreamImageSource(resizedStream))
                    using (var effect = new FilterEffect(source) { Filters = filters })
                    using (var renderer = new JpegRenderer(effect))
                    {
                        buffer = await renderer.RenderAsync();

                        using (var rotatedResizedStream = new InMemoryRandomAccessStream())
                        {
                            await rotatedResizedStream.WriteAsync(buffer);
                            await rotatedResizedStream.FlushAsync();

                            return rotatedResizedStream.CloneStream();
                        }
                    }
                }
                else
                {
                    return resizedStream.CloneStream();
                }
            }
        }
开发者ID:roachhd,项目名称:filter-explorer,代码行数:69,代码来源:PhotoModel.cs

示例13: TryWriteStreamAsync

 public static async Task<bool> TryWriteStreamAsync(this StorageFile storageFile, IRandomAccessStream stream)
 {
     stream.Seek(0);
     IBuffer buffer = new byte[stream.Size].AsBuffer();
     await stream.ReadAsync(buffer, buffer.Length, InputStreamOptions.None);
     return await TryWriteBufferAsync(storageFile, buffer);
 }
开发者ID:chenjianwp,项目名称:UWP_ToolKit_CommonLibrary,代码行数:7,代码来源:StorageManagerEx.cs


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