C# 如何在Crystal报表中显示空白图像
通过以下步骤,我将图像显示到Crystal Report 首先:我在dataset的datatable中创建了一个新列(“Image”),并将数据类型更改为System.Byte() 第二:将此图像文件拖放到我想要的位置C# 如何在Crystal报表中显示空白图像,c#,crystal-reports,C#,Crystal Reports,通过以下步骤,我将图像显示到Crystal Report 首先:我在dataset的datatable中创建了一个新列(“Image”),并将数据类型更改为System.Byte() 第二:将此图像文件拖放到我想要的位置 private void LoadReport() { frmCheckWeigher rpt = new frmCheckWeigher(); CryRe_DailyBatch report = new CryRe_DailyBatch
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();
}
//通过此函数,我将图像数据合并到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
}
私有数据表GetImageRow(数据表dt,字符串ImageName)
{
尝试
{
文件流fs;
二进制读取器br;
if(File.Exists(AppDomain.CurrentDomain.BaseDirectory+ImageName))
{
fs=新文件流(AppDomain.CurrentDomain.BaseDirectory+ImageName,FileMode.Open);
}
其他的
{
//如果照片不存在,则显示空白或不显示任何内容。
对于(int i=0;i
当我在路径上有图像时,这非常有效,但是
当用户未在指定路径上提供图像时,我想显示空白,
但我得到的空白方块根据给定的图像与边框如何删除它请帮助我。。
使用报告中的抑制功能 右键单击图像对象>>格式化对象>>填充单词suppress附近的复选框,然后单击suppress右侧的公式,然后添加所需的公式,例如:
我没有C#方面的经验,但是如果使用的工具没有给出任何路径,您可能需要尝试suppress的
suppress
选项。。类似于checkISNull(path),如果为true,则禁用图像,否则显示
在Crystal designer中打开报告,尝试右键单击图像,然后单击格式化
。检查是否设置了边框。
ISNULL({Class;1.Img})