代码之家  ›  专栏  ›  技术社区  ›  VoodooChild

文件位置到System.IO.Stream

  •  0
  • VoodooChild  · 技术社区  · 14 年前

    public void SetSource(Stream streamSource);
    

    BitmapSource ,是否有方法转换我的URI或图像文件位置并将其作为流传递?

            Uri uri = new Uri("../images/MyImage.png", UriKind.Relative);
            BitmapImage btmp1 = new BitmapImage(uri);
            WriteableBitmap btmp = new WriteableBitmap(btmp1);
    

    我在创建btmp实例时遇到一个error NULL异常(因为它需要一个BitmapImageSource)…但是我该如何得到我想要的呢?

    谢谢,

    2 回复  |  直到 14 年前
        1
  •  2
  •   SLaks    14 年前

    你可以做一个 FileStream :

    thingy.SetSource(new FileStream(path));
    
        2
  •  1
  •   SLaks    14 年前

    new BitmapImage(new Uri(path, UriKind.Absolute))
    

    如果你有一个相对路径,通过 UriKind.Relative .