来自字节数组的水晶报表图像不打印

Crystal Report image from byte array not printing(来自字节数组的水晶报表图像不打印)
本文介绍了来自字节数组的水晶报表图像不打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有类作为数据源的 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;
}

这篇关于来自字节数组的水晶报表图像不打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)