2015-04-25 1 views
1

J'ai besoin de savoir comment convertir une image bitmap en un tableau d'octets pour l'application de magasin de Windows. Voici ce que je l'ai essayé, mais il ne stocke pas les BitmapImageconvertir un bitmapImage en tableau byte pour 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

Pouvez-vous nous montrer ce que vous avez essayé jusqu'à présent? –

+0

Quel code avez-vous essayé jusqu'à présent? Si vous montrez ce que vous avez essayé, et dites quel bit ne fonctionne pas, alors vous verrez que vous aurez une meilleure réponse. –

+0

bien j'ai essayé cela, mais il est stockons pas comme un fichier Dim 'BitmapImage Comme StorageFile = Attendent Windows.Storage.StorageFile.GetFileFromApplicationUriAsync() stream Dim Comme IRandomAccessStream = Attendent file.OpenAsync (Windows.Storage.FileAccessMode.Read) décodeur Dim Comme BitmapDecoder = Attendent BitmapDecoder.CreateAsync (flux) Dim pixelData Comme PixelDataProvider = Attendent decoder.GetPixelDataAsync() Retour pixelData.DetachPixelData() » –

Répondre

0

je l'ai trouvé: 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

Enregistrez le bitmap à MemoryStream avec Bitmap.Save() puis enregistrez le MemoryStream.ToArray(). Peut-être pas l'approche la plus élégante, mais fonctionne. Je peux poster un code de travail un peu plus tard.

+0

la' bitmap.save' n'existe pas dans le cadre des fenêtres app magasin ... –

+0

Oh, je n'ai pas vu ça venir. Désolé .. – Sami

+0

Je peux cacher 'Byte()' à 'BitmapImage' mais en sens inverse je ne pouvais pas et j'ai tellement besoin de ça –