将图像插入水晶报表(Insert image to crystal reports)

526 IT屋

Insert image to crystal report I have ADO.NET data connection where i'm using

<xs:element name="Drawing" type="xs:byte" minOccurs="0" />

for image field, so how can i use that image byte data to display image in my crystal reports 2013. I'm not using any backend coding because there's possible many images in that retrieved data, Here's my data structure of table "Drawing" is image field of data which i have stored as byte enter image description here

i'm using image contained report as sub report

解决方案

I am not sure if i understood your question, but let me share something that may lead you to something useful. I understand you said there is no "backending code", but i hope this may contain some useful tip for your case.

When we use an image in Crystal Reports, it's type is base64Binary in the XSD.

In the dataset, it's type is byte[].

We save the image as a serialized string in the database. Something like that:

FileStream stream = new FileStream(filePath, FileMode.Open);
BinaryReader binreader = new BinaryReader(stream);
byte[] buffer = new byte[(int) stream.Length];
buffer = binreader.ReadBytes((int) stream.Length);
string serialized = Convert.ToBase64String(buffer)

We get it back as a byte array to put in the dataset:

byte[] buffer = Convert.FromBase64String(serialized)

In the Crystal Report design tool, we just drag the field to the document.

将图片插入水晶报表
我有ADO.NET数据连接,我使用



  xs:element name ="Drawing"type ="xs:byte"minOccurs ="0"/> 


,所以如何使用图像字节数据在我的水晶报表2013 。
我没有使用任何后端编码,因为可能有很多图像在检索的数据,
这里是我的数据结构的表"绘图"是数据的字段我存储为字节
enter image description here



我使用image


解决方案

我不知道我是否理解你的问题,但让我分享一些可能引导你到有用的东西。我理解你说没有"后台代码",但我希望这可能包含一些有用的提示为您的情况。



当我们使用水晶报表中的图像,类型是XSD中的base64Binary。



在数据集中,它的类型是byte []。



该图像作为数据库中的序列化字符串。类似的东西:



  FileStream stream = new FileStream(filePath,FileMode.Open); 
BinaryReader binreader = new BinaryReader(stream);
byte [] buffer = new byte [(int)stream.Length];
buffer = binreader.ReadBytes((int)stream.Length);
string serialized = Convert.ToBase64String(buffer)


要放入数据集:



  byte [] buffer = Convert.FromBase64String(serialized)


在Crystal报表设计工具中,我们只需将字段拖到文档。


本文地址:IT屋 » 将图像插入水晶报表