c# - How to make a byte array with an image from solution. (Windows Phone 8.1 runtime) -


i need make byte[] image, first think have save image file storagefile or something, , pass method, job:

private async task<byte[]> storagefiletobytearray(storagefile file)     {         byte[] bytearray = new byte[0];          if (null != file)         {             irandomaccessstream filestream = await file.openasync(fileaccessmode.read);              var reader = new datareader(filestream.getinputstreamat(0));             await reader.loadasync((uint)filestream.size);              bytearray = new byte[filestream.size];         }          return bytearray;     } 

but how save storagefile?

this file

this how load in bitmapimage:

bitmapimage bitmapimage = new bitmapimage(new uri("ms-appx:///assets/no_capture_receipt.png", urikind.absolute)); 

then how save image in storagefile

it's easier think.

private async task<byte[]> storagefiletobytearray(string filename)  //filename = "no_capture_receipt.png" {     var folder = await windows.applicationmodel.package.current.installedlocation.getfolderasync("assets");      var storagefile = await folder.getfileasync(filename);      var buffer = await windows.storage.fileio.readbufferasync(storagefile);      return buffer.toarray();         } 

don't forget change copy output directory of image copy if newer!


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -