我需要像這樣將條形碼圖片添加到 crpReport 中的 Barcodemat 列
r["BarcodeMat"] = ImageToByte2(bar.Encode(typebq, data, w, hh));
這是我的函式 ImageToByte2
private byte[] ImageToByte2(object img)
{
byte[] byteArray = new byte[1];
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
byteArray = stream.ToArray();
}
return byteArray;
}
我有錯誤
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
錯誤說“物件”不包含“保存”的定義,并且找不到接受“物件”型別的第一個引數的擴展方法“保存”
uj5u.com熱心網友回復:
來自barnhill/barcodelib Barcode(第 336 行),
public Image Encode(TYPE iType, string StringToEncode, int Width, int Height)
該方法與Image型別一起回傳。
因此,將img引數更改為Image型別。
using System.Drawing;
private byte[] ImageToByte2(Image img)
{
...
}
參考
barcodelib,C#條碼影像生成庫(示例部分),下載barcodelib的原始碼_GitHub_幫酷
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/347477.html
