WP8 e.ChosenPhoto到Base64字符串

时间:2013-09-17 14:15:15

标签: c# windows-phone-8 base64 bitmapimage

我正在拍摄一张Windows Phone 8应用程序。我想从e.ChosenPhoto对象获取Base64字符串,但不知道该怎么做。

代码:

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
     }
}

1 个答案:

答案 0 :(得分:1)

以下是我解决问题的方法:

        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;
        }