c# - Uploading a BitmapImage as JSON post for Windows Runtime apps -


i've got bitmapimage defined as:

bitmapimage bitmapimage = new bitmapimage(new uri("http://link.com/image.jpg")); 

now, need encode image base64 , post json. haven't found many guides on this, , when do, uses silverlight or .net libraries aren't available windows store development, think uses winrt. appreciated.

depending on scenario might able use urisource bitmapimage read image again , convert base64 string:

bitmapimage bitmapimage = new bitmapimage(new uri("http://i.stack.imgur.com/830ke.jpg?s=128&g=1"));  randomaccessstreamreference rasr = randomaccessstreamreference.createfromuri(bitmapimage.urisource); var streamwithcontent = await rasr.openreadasync();  byte[] buffer = new byte[streamwithcontent.size]; await streamwithcontent.readasync(buffer.asbuffer(), (uint)streamwithcontent.size, inputstreamoptions.none);  string base64string = convert.tobase64string(buffer); 

it seems if doing windows store app prior windows 8.1 update 1 have manually add correct namespace asbuffer() extension work, try add this:

using system.runtime.interopservices.windowsruntime; 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -