【发布时间】:2015-08-27 01:48:45
【问题描述】:
我有一张从我的手机图库中拍摄的图片,如下所示:
private void StackPanel_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
PhotoChooserTask pct = new PhotoChooserTask();
pct.Show();
pct.Completed += pct_Completed;
}
void pct_Completed(object sender, PhotoResult e)
{
BitmapImage img = new BitmapImage();
if (e.ChosenPhoto != null)
{
img.SetSource(e.ChosenPhoto);
imgphotochoser.Source = img;
}
}
现在我想通过网络服务将此图像保存在数据库中。所以,我需要将此图像转换为 base64 字符串,但我该怎么做呢?
我试过了,但它抛出了一个异常:
public string imagetobase64(image image,
system.drawing.imaging.imageformat format)
{
using (memorystream ms = new memorystream())
{
// convert image to byte[]
image.save(ms, format);
byte[] imagebytes = ms.toarray();
// convert byte[] to base64 string
string base64string = convert.tobase64string(imagebytes);
return base64string;
}
}
【问题讨论】:
-
@DGibbs:是的,请参阅我编辑的答案
-
C# 是一种区分大小写的语言
-
@DGibbs:命名空间“System”中不存在类型或命名空间名称“Drawing”(您是否缺少程序集引用?)
-
但是哪个程序集?我不知道哪个适合溺水,它也会在“保存”中出错
-
@DGibbs:当时我想添加 system.drowing dll 时会出现错误“无法将对更高版本的引用或不兼容的程序集添加到项目中”我该如何解决问题
标签: c# image windows-phone-8 base64