I have an image taken from my phone gallery, like below:
private void StackPanel_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
PhotoChooser
Simply convert the byte[]
to a base64 string
:
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
if (imgphotochoser.Source != null)
{
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)imgphotochoser.Source);
wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
bytearray = ms.ToArray();
}
}
string str = Convert.ToBase64String(bytearray);
Base64 to byte[]
:
byte[] fileBytes = Convert.FromBase64String(s);
using (MemoryStream ms = new MemoryStream(fileBytes, 0, fileBytes.Length))
{
ms.Write(fileBytes, 0, fileBytes.Length);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(ms);
return bitmapImage;
}