来自字节数组的Crystal Report图像无法打印 [英] Crystal Report image from byte array not printing

查看:41
本文介绍了来自字节数组的Crystal Report图像无法打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有类作为数据源的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 = @"\\SERVER\Printer";
    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;
}

这篇关于来自字节数组的Crystal Report图像无法打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆