i need to add barcode pic to Barcodemat column in crpReport like this
r["BarcodeMat"] = ImageToByte2(bar.Encode(typebq, data, w, hh));
and this is my function 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;
}
i have error in
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
The error said 'object' does not contain a definition for 'Save' and no extension method 'Save' accepting first argument of type 'object' could be found
CodePudding user response:
From barnhill/barcodelib Barcode
(Line 336),
public Image Encode(TYPE iType, string StringToEncode, int Width, int Height)
The method is returned with Image
type.
Hence, change img
parameter to Image
type.
using System.Drawing;
private byte[] ImageToByte2(Image img)
{
...
}
References
GitHub - barnhill/barcodelib: C# Barcode Image Generation Library (Example section)