Answered by:
How to Share image from Web in Share Contract

Question
-
Using the Share-To contract in an HTML5 app Metro App, how do you share an image from an image URL (like http://whatever.com/test.png) using the setBitmap() function?
Thanks,
Michael
Michael S. Scherotter
Principal Architect Evangelist Microsoft Corporation,
Blog, Twitter, FacebookThursday, December 8, 2011 7:36 PM
Answers
-
I was able to get it working with the following code:
var deferral = request.getDeferral(); var imageSource = Windows.Storage.Streams.StreamReference.createFromUri(new Windows.Foundation.Uri(imageUrl)); imageSource.getStreamAsync().then(function (randomAccessStream) { request.data.setBitmap(randomAccessStream); deferral.complete(); });
Thanks for the help.Michael
Michael S. Scherotter
Principal Architect Evangelist Microsoft Corporation,
Blog, Twitter, Facebook- Marked as answer by SynergistMicrosoft employee Friday, December 9, 2011 5:51 PM
Friday, December 9, 2011 5:51 PM
All replies
-
Hi Michael,
I think you are well on your way. I think you understand what needs to be done, but you want to know how to set a stream on the setBitmap function from the downloaded image. Is that correct?
-Jeff
Jeff Sanders (MSFT)Friday, December 9, 2011 3:02 PMModerator -
-
Michael,
You can get the stream from the URI using this call:
That may be enough for you to get going. If not I will see if I can get a quick sample together for you.
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, December 9, 2011 5:18 PM
Friday, December 9, 2011 5:18 PMModerator -
I was able to get it working with the following code:
var deferral = request.getDeferral(); var imageSource = Windows.Storage.Streams.StreamReference.createFromUri(new Windows.Foundation.Uri(imageUrl)); imageSource.getStreamAsync().then(function (randomAccessStream) { request.data.setBitmap(randomAccessStream); deferral.complete(); });
Thanks for the help.Michael
Michael S. Scherotter
Principal Architect Evangelist Microsoft Corporation,
Blog, Twitter, Facebook- Marked as answer by SynergistMicrosoft employee Friday, December 9, 2011 5:51 PM
Friday, December 9, 2011 5:51 PM -
Awesome! The code looks good. Thanks for sharing!
Jeff Sanders (MSFT)Friday, December 9, 2011 6:59 PMModerator