c# - Byte array to brush Windows 8.1 -


i found lot of answers on stackoverflow or internet, noone of them solved problem. closest solution found mix of , resulted in this:

inmemoryrandomaccessstream stream = new inmemoryrandomaccessstream(); using (datawriter writer = new datawriter(stream.getoutputstreamat(0))) {     writer.writebytes(foto.foto_byte);     writer.storeasync().getresults(); } bitmapimage image = new bitmapimage(); image.setsource(stream); imagebrush brush = new imagebrush(); brush.imagesource = image; preview.background = brush; 

the second part works, because used in application , did it, in windows 8.1 have problem converting byte[] inmemoryrandomaccessstream.

anyway appreciated.

ps: new writeablebitmapimage(bitmap); doesn't work in wp 8.1 :(

thanks all.

edit: preview canvas, may wrong way fill it? how initialize it

<grid x:name="rootview">     <grid.rowdefinitions>         <rowdefinition height="*"></rowdefinition>         <rowdefinition height="auto"></rowdefinition>     </grid.rowdefinitions>      <canvas x:name="preview" background="white" grid.row="0"></canvas>     <button x:name="btnelimina" horizontalalignment="center" grid.row="1" content="elimina"></button> </grid> 

i'm using this

public static class bytearrayextensions {     public static async task<bitmapimage> asbitmapimageasync(this byte[] bytearray)     {         if (bytearray == null) return null;          using (var stream = new inmemoryrandomaccessstream())         {             await stream.writeasync(bytearray.asbuffer());             var image = new bitmapimage();             stream.seek(0);             image.setsource(stream);             return image;         }     } } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -