c# - 从目录加载 WP 8 应用程序中的图像文件

标签 c# windows-phone-8 loading-image

我正在开发一个 WP 8 应用程序,我想加载一个当前在我的计算机驱动器上的图像。这是我的代码

  try
        {
            using (FileStream fileStream = File.OpenRead("\\TiltFilter\\FilterEffects\\Assets\\AlignmentGrid.png")) 
            {
                MemoryStream memStream = new MemoryStream();
                memStream.SetLength(fileStream.Length);
                fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);
            }
        }
        catch (Exception e)
        {
            string str = e.Message;
        }

它给了我类型的异常(exception)

System.Io.DirectoryNotFoundexceptionand the message isCould not find a part of the path 'C:\TiltFilter\FilterEffects\Assets\AlignmentGrid.png'.

有人可以帮助我如何在 WP8 上的内存流中加载图像

谢谢

最佳答案

您需要将图像作为Content 添加到项目中,并使用GetResourceStream 访问图像流:

var resource = App.GetResourceStream(new Uri("Assets/AlignmentGrid.png", UriKind.Relative));
var buffer = new byte[resource.Stream.Length];
resource.Stream.Read(buffer, 0, buffer.Length);

关于c# - 从目录加载 WP 8 应用程序中的图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17292041/

相关文章:

html - Windows Phone 8 IE10 Mobile 溢出滚动不起作用

c# - DataBinding 到单例属性的属性

html - 加载图片有时不出现

c# - 如何制作 System.Net.Mail MailMessage 的模型?

c# - Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词

c# - Windows 商店应用程序中的密码散列

c# - Firebase:在 Windows Phone 上使用 Accept: text/event-stream

javascript - 检查图像加载失败

c# - 在 Unity 中捕获异常