Pregunta

I have a Windows Phone 8 Application where I am taking a picture. I would like to get the Base64 String from the e.ChosenPhoto object but not sure how to go about it.

Code:

private void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        var bmp = new BitmapImage();
        bmp.SetSource(e.ChosenPhoto);
        imgPhoto.Source = bmp;
        imgPhoto.Stretch = Stretch.Uniform;

        // Get the base64 String from the e.ChosenPhoto or the bmp object
     }
}
¿Fue útil?

Solución

The following is how I solved the issue:

        byte[] bytearray = null;

        using (var ms = new MemoryStream())
        {
            if (imgPhoto.Source != null)
            {
                var wbitmp = new WriteableBitmap((BitmapImage) imgPhoto.Source);

                wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
                bytearray = ms.ToArray();
            }
        }
        if (bytearray != null)
        {
            Sighting.Instance.ImageData = Convert.ToBase64String(bytearray);
            PhotoModel.Instance.BitmapImage = bitmapImage;
        }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top