2015-04-25 48 views
1

我需要知道如何将bitmap-image转换为windows store应用程序的字节数组。 这里是我试过,但它不会将位图保存的BitmapImage将bitmapImage转换为用于windows store的字节数组

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() 
+2

你能告诉我们你尝试过什么到目前为止? –

+0

到目前为止您尝试过哪些代码?如果你显示你已经尝试了什么,并说出哪个位不起作用,那么你会发现你会得到更好的回应。 –

+0

以及我试过,但它不是存储像的BitmapImage '点心文件作为StorageFile =等待Windows.Storage.StorageFile.GetFileFromApplicationUriAsync() 昏暗流作为IRandomAccessStream =等待file.OpenAsync(Windows.Storage.FileAccessMode.Read) 昏暗解码器作为BitmapDecoder =等待BitmapDecoder.CreateAsync(流) 昏暗PixelData取出作为PixelDataProvider =等待decoder.GetPixelDataAsync() 返回pixelData.DetachPixelData()” –

回答

0

我发现: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 
0

保存到MemoryStreamBitmap.Save()然后保存MemoryStream.ToArray()。也许不是最优雅的方法,但工程。 我可以稍后发布工作代码。

+0

的'bitmap.save'不窗户商店应用的框架中存在... –

+0

哦,没有看到即将到来。对不起.. – Sami

+0

我可以将'Byte()'转换为'BitmapImage',但是反过来我不能,我需要这么多 –

相关问题