在WinRT中将BitmapImage转换为Base64String

时间:2015-08-06 07:41:28

标签: c#-4.0 windows-runtime windows-8.1 winrt-xaml winrt-async

我想在我的Windows 8.1应用中将BitmapImage转换为base64string。 代码:

protected void UpdateSignatureAsync(BitmapImage bitmapImage, string fileName, long vehicleInsRecID)
{


    WriteableBitmap writimage = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
    using (MemoryStream ms = new MemoryStream())
    {
        WriteableBitmapExtensions.FromStream(writimage, ms);
        Stream s1 = writimage.PixelBuffer.AsStream();
        s1.CopyTo(ms);
        writimage.PixelBuffer.AsStream();
        var ic = new ImageCapture
        {
            ImageBinary = Convert.ToBase64String(ms.ToArray()),/// this line
            CaseServiceRecId = vehicleInsRecID,
            FileName = fileName
        };
        await UpdateImageAsync(ic);
    }

1 个答案:

答案 0 :(得分:0)

我对您的问题没有确切的答案,但如果您的StorageFile是图片,那么您可以使用{{将此图片转换为Base64字符串1}}以下类中的方法:

GetBase64FromImageFile