So Im trying trying to load an image into a WriteableBitmap but I’m getting a NullReferenceException. Can’t figure out why because I think this used to work before
BitmapImage b = new BitmapImage(new Uri(@"images/Car.jpg", Urikind.Relative));
WriteableBitmap wb = new WriteableBitmap(b);
thats it. I have the car image as a resource in my project. It works fine as I can create a Image control and set its source to the BitmapImage and display it.
Thanks
As seen from other SO questions, it seems that the reason you get the null reference exception is that BitmapImage.CreateOptions Property default value is
BitmapCreateOptions.DelayCreation. You can set it toBitmapCreateOptions.Noneand createWriteableBitmapafter image loaded:Using that code, the
WritableBitmapwill wait until theBitmapImageis loaded, and then it will be able to be assigned to theWritableBitmap.