本文整理汇总了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);
}
}
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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));
}
}
示例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);
}
}
示例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);
}
}