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