I am trying to retrieve an image from an Embedded resource, and displaying it in its RAW DATA format (i.e. -> junk text data).
我试图从嵌入式资源中检索图像,并以RAW DATA格式显示它(即 - >垃圾文本数据)。
Basically, I am running into a wall with everything I attempt. Can someone show me how to do this properly?
基本上,我遇到了我尝试过的所有东西。有人能告诉我如何正确地做到这一点吗?
1 个解决方案
#1
You can use the following msdn ref
您可以使用以下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.
这将为您提供一个Stream,然后您可以使用代码引用转换为几乎是原始数据的字节数组。
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
#1
You can use the following msdn ref
您可以使用以下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.
这将为您提供一个Stream,然后您可以使用代码引用转换为几乎是原始数据的字节数组。
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