简体   繁体   English

来自字节数组的Crystal Report图像无法打印

[英]Crystal Report image from byte array not printing

I have a Crystal Report with a class as a data source. 我有一个使用类作为数据源的Crystal Report。 I have a byte array which I am passing a bitmap to but it isn't printing on the Crystal Report. 我有一个字节数组,正在将一个位图传递给它,但是它没有在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 = @"\\SERVER\Printer";
    d.PrintToPrinter(1, false, 0, 0);
}

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. 我正在使用一个类来创建EAN条形码,该部分可正确呈现为图像文件,但在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. 我一直使用这种方法将图像毫无问题地发送到Crystal Reports。

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;
}

To be able to show the image on the report, when you pull the image Field of your DataSet, it has to be IBlobFieldObject in CR. 为了能够在报表上显示图像,当您拉出DataSet的图像字段时,它必须是CR中的IBlobFieldObject I had a lot of trouble achieving this. 我很难做到这一点。 Eventually i removed the DataSet from the report (through 'Database expert') and re-added it. 最终,我从报表中删除了数据集(通过“数据库专家”)并重新添加了它。 Also make sure, that your Image field is set to byte[] in the DataSet. 还要确保将您的Image字段设置为DataSet中的byte []。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM