Resource from assembly as a stream

前端 未结 4 1410
予麋鹿
予麋鹿 2020-12-05 02:43

I have an image in a C# WPF app whose build action is set to \'Resource\'. It\'s just a file in the source directory, it hasn\'t been added to the app\'s resource collection

4条回答
  •  感动是毒
    2020-12-05 03:23

    You're probably looking for Application.GetResourceStream

    StreamResourceInfo sri = Application.GetResourceStream(new Uri("Images/foo.png"));
    if (sri != null)
    {
        using (Stream s = sri.Stream)
        {
            // Do something with the stream...
        }
    }
    

提交回复
热议问题