c# - After fileStream.CopyTo(memoryStream), memoryStream is null -


so, have function, gets bitmapimage, need save iso storage , convert base64 (for sending server). however, copying filestream memorystream not successful.

public void setimage(bitmapimage bitmap) {     if (isofiles.fileexists(settings.file_avatar_jpg))         isofiles.deletefile(settings.file_avatar_jpg);      var filestream = isofiles.createfile(settings.file_avatar_jpg);     var wb = new writeablebitmap(bitmap);     wb.savejpeg(filestream, 120, 120, 0, 85); // file saved       var memorystream = new memorystream();     filestream.copyto(memorystream);          // here, memorystream null     byte[] result = memorystream.toarray();     filestream.close();      var base64 = convert.tobase64string(result); } 

stream.copyto copies current position of filestream has been changed savejpeg() need reset it;

var memorystream = new memorystream();  filestream.position = 0; filestream.copyto(memorystream);   

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -