我有一个带有类作为数据源的 Crystal Report.我有一个字节数组,我将位图传递给它,但它没有在 Crystal Report 上打印.请在下面查看我的代码.
I have a Crystal Report with a class as a data source. I have a byte array which I am passing a bitmap to but it isn't printing on the Crystal Report. Please see my code below.
var d = new Label();
var eanCreator = new CreateEan();
var bf = new BinaryFormatter();
using (var ms = new MemoryStream())
{
bf.Serialize(ms, eanCreator.createBitmap(1.5f, "1234567890"));
var byteArray = ms.ToArray();
var ld = new LabelData
{
PartNumber = "123",
EanData = byteArray
};
d.SetDataSource(new List<LabelData> {ld});
d.PrintOptions.PrinterName = @"\SERVERPrinter";
d.PrintToPrinter(1, false, 0, 0);
}
打印出来了,除了图像之外的所有数据都存在.我正在使用一个类来创建 EAN 条码,这部分可以正确呈现为图像文件,但在 Crystal Reports 中无法识别.
The print comes out, all data except the image is present. I am using a class to create an EAN barcode, this part renders correctly to an image file, but just won't recognise it within Crystal Reports.
这个方法和你的代码类似.我一直使用这种方法将图像发送到 Crystal Reports 没有问题.
This method is similar to your code. I use this method all the time to send an image to Crystal Reports without problems.
public static byte[] ConvertImageToByte(Image Value)
{
if (Value != null)
{
MemoryStream fs = new MemoryStream();
((Bitmap)Value).Save(fs, ImageFormat.Jpeg);
byte[] retval= fs.ToArray();
fs.Dispose();
return retval;
}
return null;
}
这篇关于来自字节数组的水晶报表图像不打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!