【发布时间】:2017-08-31 14:16:07
【问题描述】:
通过以下过程,我正在向 Crystal Report 显示图像
首先:我在数据集的数据表中创建了一个新列(“图像”)并将 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
}
当我在路径上有图像但 当用户未在指定路径上提供图像时,我想显示空白空间, 但是根据给定的带有边框的图像,我得到了空白正方形,如何将其删除,请帮助我..
【问题讨论】:
-
我在 C# 方面没有经验,但您可能需要尝试
supress选项来抑制当使用的没有提供任何路径时.. 像检查ISNull(path) and if it is true supress the image else display -
在 Crystal Designer 中打开报表,尝试右键单击图像,然后单击
Format。检查是否设置了边框。
标签: c# crystal-reports