0

我有一个正在拍照的 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
     }
}
4

1 回答 1

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;
        }
于 2013-09-18T12:48:47.220 回答