[英]Convert Image to Base64String
我需要一些将图像转换为base64string的帮助。 我曾在stackoverflow中使用类似问题的解决方案,但发生了错误。
使用的解决方案: 将图像转换为wp8中的base64
问题出在我曾经设置为可写位图的图像源上,但结果是一个空异常。
这是我的图像来源:
image123.Source = new BitmapImage(new Uri("/correct1.jpg", UriKind.Relative));
此行发生错误:
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image123.Source);
错误:
An exception of type 'System.NullReferenceException' occurred in System.Windows.ni.dll but was not handled in user code
我现有的代码作为参考:
image123.Source = new BitmapImage(new Uri("/correct1.jpg", UriKind.Relative));
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
if (image123.Source != null)
{
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image123.Source);
wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
bytearray = ms.ToArray();
}
}
str = Convert.ToBase64String(bytearray);
binarytxt.Text = str;
我真的很想得到帮助,因为这是我的主要项目。 提前致谢!
这些代码正常工作,只是需要一个EventHandler 。 我曾经使用Button_Click侦听器来运行代码,并且运行良好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.