将 bitmapImage 转换为 windows 存储的字节数组
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()
。也许不是最优雅的方法,但有效。
稍后我可以 post 一个工作代码。
我找到了 :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
我需要知道如何将位图图像转换为 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()
。也许不是最优雅的方法,但有效。
稍后我可以 post 一个工作代码。
我找到了 :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