是否可以将图像/图片存储(编码)到pdf417条形码中?如果可以,是否有任何教程或示例代码?
条形码不能仅仅保存数据库中图像的引用。客户还希望能够存储他想要的任何图像。
谢谢。
是否可以将图像/图片存储(编码)到pdf417条形码中?如果可以,是否有任何教程或示例代码?
条形码不能仅仅保存数据库中图像的引用。客户还希望能够存储他想要的任何图像。
谢谢。
正如ssasa提到的那样,您可以将图像存储为byte
数组:
public static byte[] GetBytes(Image image)
{
byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
// you may want to choose another image format than PNG
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
byteArray = stream.ToArray();
}
return byteArray;
}
如果必须为 string
类型,您可以对其进行 base64 编码:
public static string GetBase64(Image image)
{
Image yourImage;
// using the function from the first example
var imageBytes = GetBytes(yourImage);
var encodedString = Convert.ToBase64String(imageBytes);
return Encoding.UTF8.GetBytes(encodedString);
}