将资源转换为byte []

Goa*_*ker 2 c# wpf

我无法将图像资源转换为byte [].

例如,我有以下资源:

pack://application:,,,/AppName;component/Assets/Images/sampleimage.jpg
Run Code Online (Sandbox Code Playgroud)

在我的程序中.如何将其转换为byte [].

我尝试过使用BitMapImage,但是ImageSource在初始化后最终为null.

Goa*_*ker 5

这似乎有效:

var info = Application.GetResourceStream(uri);
var memoryStream = new MemoryStream();
info.Stream.CopyTo(memoryStream);
return memoryStream.ToArray();
Run Code Online (Sandbox Code Playgroud)