3

I have a silverlight 5 project called Kinemat.AuthoringTool. Inside this project i have a folder called Backgrounds and there i have some images (their Build Action is Content). I want to access an image's stream and then upload that image on a server. After some research on msdn i use the following code:

StreamResourceInfo streamResourceInfo = 
                      Application.GetResourceStream(new Uri("PathToPutHere"));
Stream imageStream = streamResourceInfo.Stream;

of course using the path "/Backgrounds/imageName" does not work. What is the correct path then?

4

1 回答 1

1

Embeded相反,通过包含 dll 中的命名空间和名称来制作具有构建属性和路径的图像。我已经为流创建了这样一个图像提取器(可以在 Silverlight 之外使用

public static Stream GetImage(string resourceName)
{
    var assembly = Assembly.GetExecutingAssembly();

    var stream = assembly.GetManifestResourceStream(resourceName);

    if (stream == null)
        throw new ArgumentException(
             $"No resource with name {resourceName} in {assembly.FullName}");

    return stream;
}
于 2019-07-24T15:50:00.547 回答