views:

42

answers:

2

Hi Guys,

I have this method

public void SetSource(Stream streamSource);

which sets the source of BitmapSource, is there a way to convert my URI or my image file location and pass it as a stream?

(another issue):

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

I am getting an error NULL exception when creating an instance of btmp (because it is expecting a BitmapImageSource)...but how do I get what I am after?

thanks,

Voodoo

+2  A: 

You can make a FileStream:

thingy.SetSource(new FileStream(path));
SLaks
do I have to give Absolute path? what if I want to tell it that it's in the images folder from the root ?
VoodooChild
I tried [new BitmapSource().SetSource(new FileStream(@"C:\images\myimage.png", FileMode.Open));" ...but it is complaining that Cannot create an instance of the abstract class or interface 'System.Windows.Media.Imaging.BitmapSource'
VoodooChild
Change it to `new BitmapImage()`.
SLaks
see my edit please.
VoodooChild
+1  A: 

You can simply write

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

If you have a relative path, pass UriKind.Relative.

SLaks
Yeah, I have tried that as well. But I am always getting NULL exception when using the BitMapImage object....could it be because my xap is in another directory? how do I make sure that my URI is not failing?
VoodooChild