【发布时间】:2015-08-06 07:41:28
【问题描述】:
我想在我的 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);
}
【问题讨论】:
-
您面临的具体问题是什么?
-
...所以您想将图像数据保存为位图?还是您要保存原始像素?
-
此代码错误。 BitmapImage 没有转换 WriteableBitmap 。它只是取 BitmapImage 字节数组(ms.ToArray())的高度和宽度,每个字节都是 0。
-
您在不是
async的方法中使用了await- 您的示例代码还有其他问题。
标签: c#-4.0 windows-runtime windows-8.1 winrt-xaml winrt-async