Problem while creating writeable bitmap from stream

Oct 30, 2012 at 6:01 AM
Edited Oct 30, 2012 at 6:02 AM

Hello team,

I have an object of IRandomAccessStream and i need to create writeable from this stream .

For this i am trying this asbelow. Here dockpic is stream object and image is image element in xaml page.

WriteableBitmap writeableBmp = await new WriteableBitmap(0,0).FromStream(dockpic);
image.Source = writeableBmp;

My stream is right because i tried in normal case as

BitmapImage dockimage = new BitmapImage();
image.Source = dockimage;

In this case image is displaying rt.

Please guide me where i am doing wrong or any other way for this ?

Thanks in Advance

Oct 30, 2012 at 8:23 AM

Should work. Try 

WriteableBitmap writeableBmp = await new WriteableBitmap(1, 1).FromStream(dockpic);
Oct 30, 2012 at 8:53 AM

Hi ,

I just tried , But image is not appearing on screen. Same op as before.

any other way ?

Nov 17, 2012 at 3:37 PM
Edited Nov 17, 2012 at 3:41 PM

I'm having that exact same problem.  From what I can tell my WriteableBitmap never gets any data from the stream.  If I create a BitmapImage using the same stream it works just fine when I assign it to the source of the image.  

If I use WriteableBitmap.SetSource(stream) it works fine too, but then I can't use WriteableBitmapEX extensions because I get memory errors. 

Did you ever find a solution vivekdeshmukh?

Nov 17, 2012 at 10:40 PM

Try use SetSourceAsync method instead of FromStream method.

Nov 17, 2012 at 11:23 PM

Thanks for the suggestion vasek7.  When I use .SetSource(stream) or .SetSourceAsync(stream) it does work when setting the resulting writeablebitmap to the source of an image, but if I try to use any WriteableBitmapEX extensions on the writeablebitmap I get this exception:  Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Someone else was getting that exception in another thread and they were told to use .FromStream().  Doing that does avoid the errors, but the resulting writeablebitmap is always empty.

Nov 18, 2012 at 6:40 AM

Please provide a short reproduction VS project. It works for me. I need to look into it in order to help here.

Make sure you assign the return value FromStream.

- rene