-1
Private Function BufferFromImage(imageSource As BitmapImage) As Byte()
    If Not IsNothing(imageSource) Then
        Dim encoder As New BmpBitmapEncoder
        encoder.Frames.Add(BitmapFrame.Create(imageSource))

        Using ms As New MemoryStream
            encoder.Save(ms)
            Return ms.GetBuffer
        End Using
    End If

    Return Nothing
End Function

That function takes a long processing speed. I want a faster process. What should I do?

(Not WindowsPhone. Used WPF VB.net)

  • Do you want to get just the raw pixel data, or does it have to be an encoded buffer, like you have now? – Clemens Nov 08 '14 at 08:40

1 Answers1

-2

To convert to a byte[] you can use a MemoryStream:

byte[] data;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
using(MemoryStream ms = new MemoryStream())
 {
  encoder.Save(ms);
  data = ms.ToArray();
 }
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100