[英]convert a bitmapImage to byte array for windows store
I need to know how to convert a bitmap-image to a byte array for windows store application. 我需要知道如何将位图图像转换为Windows应用程序的字节数组。 Here is what I have tried but it does not store the bitmapImage
这是我尝试过的内容,但不存储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()
Save the bitmap to MemoryStream
with Bitmap.Save()
and then save the MemoryStream.ToArray()
. 使用
Bitmap.Save()
将位图保存到MemoryStream
,然后保存MemoryStream.ToArray()
。 Maybe not the most elegant approach, but works. 也许不是最优雅的方法,但是有效。 I can post a working code a bit later.
我可以稍后再发布工作代码。
I found it :D 我找到了: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.