[英]WP8 e.ChosenPhoto to Base64 String
我有一個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
}
}
以下是我解決問題的方法:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.