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
Post a Comment