1
 public partial class MainWindow : Window
    {
        System.Reflection.AssemblyName aName;
        System.Reflection.Assembly asm;
        public MainWindow()
        {
            InitializeComponent();

            aName = System.Reflection.AssemblyName.GetAssemblyName(
            @"C:\Users\Adam\Documents\Visual Studio 2012\Projects\WPFResources\WPFResources\bin\Release\WPFResources.dll");

            asm = System.Reflection.Assembly.Load(aName);

            string[] manifest = asm.GetManifestResourceNames();
            image1 =
        }

这就是我不知道如何让它工作的地方。在 Winforms 中,我只需创建一个新位图,并在位图的构造函数中传入来自 DLL 的流及其清单位置...

4

2 回答 2

1

您可以使用BitmapImage.StreamSource它将允许您从 System.IO.Stream 创建图像。

看看这是否适合你

asm = System.Reflection.Assembly.Load(aName)
string[] manifest = asm.GetManifestResourceNames();

using (UnmanagedMemoryStream stream = (UnmanagedMemoryStream)asm.GetManifestResourceStream(manifest[0]))//The Index of the Image you want to use
{
    using (MemoryStream ms1 = new MemoryStream())
    {
        stream.CopyTo(ms1);
        BitmapImage bmi = new BitmapImage();
        bmi.BeginInit();
        bmi.StreamSource = new MemoryStream(ms1.ToArray());
        bmi.EndInit();
        image1.Source  = bmi; //The name of your Image Control
    }

}
于 2013-02-11T06:48:33.380 回答
0

创建一个ResourceManager,在 ctor 中为他提供“基本名称”-资源文件的名称(一个程序集可以包含许多资源集),以及该程序集在哪里寻找资源。

ResourceManager resMan= new ResourceManager("MainWindowResources",asm);
Stream imageStream= resMan.GetStream("Image1");
于 2013-02-11T03:11:22.217 回答