![](/img/trans.png)
[英]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.