从图像创建字节数组 [英] Creating a Byte array from an Image
本文介绍了从图像创建字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从图像创建字节数组的最佳方法是什么?我见过很多方法,但在 WinRT 中它们都不起作用.
What is the best way to create a byte array from an Image? I have seen many methods but in WinRT none of them worked.
推荐答案
static class ByteArrayConverter
{
public static async Task<byte[]> ToByteArrayAsync(StorageFile file)
{
using (IRandomAccessStream stream = await file.OpenReadAsync())
{
using (DataReader reader = new DataReader(stream.GetInputStreamAt(0)))
{
await reader.LoadAsync((uint)stream.Size);
byte[] Bytes = new byte[stream.Size];
reader.ReadBytes(Bytes);
return Bytes;
}
}
}
}
这篇关于从图像创建字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文