通过以下程序我将图像显示到Crystal Report
首先:我在数据集的数据表中创建了一个新列(" Image"),并将DataType更改为System.Byte()
第二步:将此图像拖放到我想要的位置。
private void LoadReport()
{
frmCheckWeigher rpt = new frmCheckWeigher();
CryRe_DailyBatch report = new CryRe_DailyBatch();
DataSet1TableAdapters.DataTable_DailyBatch1TableAdapter ta = new CheckWeigherReportViewer.DataSet1TableAdapters.DataTable_DailyBatch1TableAdapter();
DataSet1.DataTable_DailyBatch1DataTable table = ta.GetData(clsLogs.strStartDate_rpt, clsLogs.strBatchno_Rpt, clsLogs.cmdeviceid); // Data from Database
DataTable dt = GetImageRow(table, "Footer.Jpg");
report.SetDataSource(dt);
crv1.ReportSource = report;
crv1.Refresh();
}
//通过此函数,我将My Image数据合并到dataTable
private DataTable GetImageRow(DataTable dt, string ImageName)
{
try
{
FileStream fs;
BinaryReader br;
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + ImageName))
{
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + ImageName, FileMode.Open);
}
else
{
// if photo does not exist show the Blank Space or Show Nothing
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i]["Image"] = DBNull.Value ;
}
return dt;
}
// initialise the binary reader from file streamobject
br = new BinaryReader(fs);
// define the byte array of filelength
byte[] imgbyte = new byte[fs.Length + 1];
// read the bytes from the binary reader
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i]["Image"] = imgbyte;
}
br.Close();
// close the binary reader
fs.Close();
// close the file stream
}
catch (Exception ex)
{
// error handling
MessageBox.Show("Missing " + ImageName + " in application folder");
}
return dt;
// Return Datatable After Image Row Insertion
}
这个作品当我在路径上有图像时完美无缺 我想在用户未指定路径上的图像时显示空白空间, 但是我得到了空白的Square,因为给定的图像有边框如何删除它请帮帮我..
答案 0 :(得分:2)
使用报告中的抑制功能,
右键单击图像对象&gt;&gt;格式对象&gt;&gt;填写单词抑制附近的复选框,然后单击禁止右侧的公式然后添加您需要的公式,如:
ISNULL({Class;1.Img})