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


C# InMemoryRandomAccessStream.WriteAsync方法代码示例

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


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

示例1: ConvertToGrayScale

        public async Task<byte[]> ConvertToGrayScale(byte[] imageBytes, int height, int width)
        {
            using (InMemoryRandomAccessStream rasStream = new InMemoryRandomAccessStream())
            {
                await rasStream.WriteAsync(imageBytes.AsBuffer());
                var decoder = await BitmapDecoder.CreateAsync(rasStream);
                var pixelData = await decoder.GetPixelDataAsync();
                var pixels = pixelData.DetachPixelData();

                if (_filter == null)
                    _filter = new ImageFilter();

                await _filter.ToGrayScale(pixels.AsBuffer());

                BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, rasStream);
                encoder.SetPixelData(decoder.BitmapPixelFormat, BitmapAlphaMode.Ignore, (uint)width, (uint)height, decoder.DpiX, decoder.DpiY, pixels);
                await encoder.FlushAsync();

                using (BinaryReader br = new BinaryReader(rasStream.AsStreamForRead()))
                {
                    rasStream.Seek(0);
                    return br.ReadBytes((int)rasStream.AsStreamForRead().Length);
                }
            }
        }
开发者ID:janaknm,项目名称:HelloWorld,代码行数:25,代码来源:PictureService.cs

示例2: Should_produce_read_bytes_hash

        public async Task Should_produce_read_bytes_hash(int bufferSize)
        {
            var data = CryptographicBuffer.GenerateRandom(2048);

            var expected = HashAlgorithmProvider
                .OpenAlgorithm(HashAlgorithmNames.Sha256)
                .HashData(data);

            using (var file = new InMemoryRandomAccessStream())
            {
                await file.WriteAsync(data);
                file.Seek(0);

                var buffer = WindowsRuntimeBuffer.Create(bufferSize);

                using (var hashed = new HashedInputStream(file))
                {
                    for (var i = 0; i < 8; i++)
                    {
                        await hashed.ReadAsync(
                            buffer, buffer.Capacity);
                    }

                    var hash = hashed.GetHashAndReset();
                    Assert.Equal(expected.ToArray(), hash.ToArray());
                }
            }
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:28,代码来源:HashedInputStreamTests.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: ConvertToInMemoryStream

 public static async Task<InMemoryRandomAccessStream> ConvertToInMemoryStream(byte[] arr)
 {
     var randomAccessStream = new InMemoryRandomAccessStream();
     await randomAccessStream.WriteAsync(arr.AsBuffer());
     randomAccessStream.Seek(0);
     await randomAccessStream.FlushAsync(); // TODO: don't sure it's needed
     return randomAccessStream;
 }
开发者ID:damonslu,项目名称:Charity,代码行数:8,代码来源:ConvertionExtensions.cs

示例5: mjpeg_FrameReady

		private async void mjpeg_FrameReady(object sender, FrameReadyEventArgs e)
		{
			InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
			await stream.WriteAsync(e.FrameBuffer);
			stream.Seek(0);
			_bmp.SetSource(stream);
			image.Source = _bmp;
		}
开发者ID:robdobsn,项目名称:RdCamViewSysTray,代码行数:8,代码来源:MainPage.xaml.cs

示例6: ToRandomAccessStream

 /// <summary>
 /// 将Stream转换成IRandomAccessStream
 /// </summary>
 /// <param name="stream"></param>
 /// <returns></returns>
 public static async Task<IRandomAccessStream> ToRandomAccessStream(this Stream stream)
 {
     var buffer = CryptographicBuffer.CreateFromByteArray(stream.GetBytes());
     InMemoryRandomAccessStream inme = new InMemoryRandomAccessStream();
     await inme.WriteAsync(buffer);
     inme.Seek(0);
     return inme;
 }
开发者ID:king89,项目名称:MangaViewer,代码行数:13,代码来源:StreamExtention.cs

示例7: AsRandomAccessStreamAsync

        public static async Task<IRandomAccessStream> AsRandomAccessStreamAsync(this byte[] array)
        {
            var stream = new InMemoryRandomAccessStream();
            await stream.WriteAsync(array.AsBuffer());
            stream.Seek(0);

            return stream;
        }
开发者ID:mdabbagh88,项目名称:UniversalImageLoader,代码行数:8,代码来源:ByteArrayExtension.cs

示例8: client_ColorFrameReady

		private async void client_ColorFrameReady(object sender, ColorFrameData e)
		{
			InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
			await stream.WriteAsync(e.PixelBuffer);
			stream.Seek(0);
			_colorBitmap.SetSource(stream);
			this.Color.Source = _colorBitmap;
		}
开发者ID:Cocotus,项目名称:kinect,代码行数:8,代码来源:MainPage.xaml.cs

示例9: SetSource

 public void SetSource(byte[] bytes)
 {
     var ms = new InMemoryRandomAccessStream();
     ms.WriteAsync(bytes.AsBuffer());
     ms.FlushAsync().AsTask().Wait();
     ms.Seek(0);
     bitmap = new BitmapImage();
     bitmap.SetSource(ms);
 }
开发者ID:hugoterelle,项目名称:mvvmcross-bitmap-plugin,代码行数:9,代码来源:MvxWindowsStoreBitmap.cs

示例10: AsBitmapImageAsync

 public static async Task<BitmapImage> AsBitmapImageAsync(this IBuffer @this)
 {
     var img = new BitmapImage();
     using (var stream = new InMemoryRandomAccessStream())
     {
         await stream.WriteAsync(@this);
         stream.Seek(0);
         await img.SetSourceAsync(stream);
     }
     return img;
 }
开发者ID:tapanila,项目名称:HockeySDK-Windows,代码行数:11,代码来源:CanvasExtensions.cs

示例11: ByteArrayToBitmapImageAsync

		public static async Task<BitmapImage> ByteArrayToBitmapImageAsync(byte[] byteArray)
		{
			var bitmapImage = new BitmapImage();

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

			bitmapImage.SetSource(stream);
			return bitmapImage;
		}
开发者ID:0xdeafcafe,项目名称:SnapDotNet,代码行数:11,代码来源:ImageConverter.cs

示例12: Headers_should_detect_not_supported_files

        public async Task Headers_should_detect_not_supported_files()
        {
            using (var file = new InMemoryRandomAccessStream())
            {
                await file.WriteAsync(
                    CryptographicBuffer.GenerateRandom(1024));

                file.Seek(0);
                var result = await FileFormat.Headers(file);

                Assert.Null(result.Headers);
                Assert.Equal(FileFormats.NotSupported, result.Format);
            }
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:14,代码来源:FileFormatTests.cs

示例13: Should_detect_corrupt_data

        public async Task Should_detect_corrupt_data()
        {
            using (var input = new InMemoryRandomAccessStream())
            {
                await CopyData(input, "IO.HashedBlockStream.bin");

                input.Seek(200);
                await input.WriteAsync(CryptographicBuffer.GenerateRandom(8));

                input.Seek(0);
                await Assert.ThrowsAsync<InvalidDataException>(
                    () => HashedBlockFileFormat.Read(input));
            }
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:14,代码来源:HashedBlockFileFormatTests.cs

示例14: Headers_should_detect_1x_file_format

        public async Task Headers_should_detect_1x_file_format()
        {
            using (var file = new InMemoryRandomAccessStream())
            {
                await file.WriteAsync(CryptographicBuffer
                    .DecodeFromHexString("03D9A29A65FB4BB5"));

                file.Seek(0);
                var result = await FileFormat.Headers(file);

                Assert.Null(result.Headers);
                Assert.Equal(FileFormats.KeePass1x, result.Format);
            }
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:14,代码来源:FileFormatTests.cs

示例15: Headers_should_detect_new_format

        public async Task Headers_should_detect_new_format()
        {
            using (var file = new InMemoryRandomAccessStream())
            {
                // Schema: 4.01
                await file.WriteAsync(CryptographicBuffer
                    .DecodeFromHexString("03D9A29A67FB4BB501000400"));

                file.Seek(0);
                var result = await FileFormat.Headers(file);

                Assert.Null(result.Headers);
                Assert.Equal(FileFormats.NewVersion, result.Format);
            }
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:15,代码来源:FileFormatTests.cs


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