Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

c# - Insert image to crystal reports

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...