Search code examples
vb.netimageembedded-resource

RAW Data from embedded resource image


I am trying to retrieve an image from an Embedded resource, and displaying it in its RAW DATA format (i.e. -> junk text data).

Basically, I am running into a wall with everything I attempt. Can someone show me how to do this properly?


Solution

  • You can use the following msdn ref

    System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(fileName)
    

    That will give you a Stream which you can then use code cite to convert to a byte array which is pretty much the raw data.

    private Function GetStreamAsByteArray(ByVal stream As System.IO.Stream) As Byte()
    Dim streamLength As Integer = Convert.ToInt32(stream.Length)
    Dim fileData As Byte() = New Byte(streamLength) {}
    ' Read the file into a byte array
    stream.Read(fileData, 0, streamLength)
    stream.Close()
    Return fileData
    End Function