[英]C# Windows 8 Store (Metro, WinRT) Byte array to BitmapImage
[英]convert a bitmapImage to byte array for windows store
我需要知道如何将位图图像转换为Windows应用程序的字节数组。 这是我尝试过的内容,但不存储bitmapImage
Dim file As StorageFile = Await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync()
Dim stream As IRandomAccessStream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Dim decoder As BitmapDecoder = Await BitmapDecoder.CreateAsync(stream)
Dim pixelData As PixelDataProvider = Await decoder.GetPixelDataAsync()
Return pixelData.DetachPixelData()
使用Bitmap.Save()
将位图保存到MemoryStream
,然后保存MemoryStream.ToArray()
。 也许不是最优雅的方法,但是有效。 我可以稍后再发布工作代码。
我找到了:D
Async Function bitmapTObyte(ByVal bitmapimage1 As StorageFile) As Task(Of Byte())
Dim fileBytes As Byte() = Nothing
Using stream As IRandomAccessStreamWithContentType = Await bitmapimage1.OpenReadAsync()
fileBytes = New Byte(stream.Size - 1) {}
Using reader As New DataReader(stream)
Await reader.LoadAsync(CUInt(stream.Size))
reader.ReadBytes(fileBytes)
Return fileBytes
End Using
End Using
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.