如何在Crystal报表中显示空白图像 [英] How to Show Blank Image In Crystal report
问题描述
通过以下过程,我正在将图像显示到Crystal报表中
By Below Procedure I am Displaying Image to Crystal Report
首先:我在数据集的数据表中创建了一个新列(图像)并更改了数据类型到System.Byte()
First: I created a New Column ("Image") in a datatable of the dataset and change the DataType to System.Byte()
第二个:将此图像拖放到我想要的位置。
Second : Drag And drop this image Filed Where I want.
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中
// By this Function I merge My Image data into 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
}
当我在路径上有图像但是
时,这很理想,当用户在指定路径上不给图像时,
我想显示空白-
但是我得到了空白图像请帮助我..
this Works Perfectly when I have Image on path but I want to Show Empty- blank Space when user Not Give Image on Specify path, But I get blank Square as per given Image with border how to remove it please help me ..
推荐答案
使用报告自身的抑制功能
Use the suppress function from the report it self,
右键单击图像对象>>格式对象>>填充抑制一词旁边的复选框,然后单击抑制右边的公式,然后添加所需的公式,例如:
Right click on the image object >> format object >> Fill the check box near the word suppress then click on the formula on the right of suppress then add the formula you require some thing like:
ISNULL({Class;1.Img})
这篇关于如何在Crystal报表中显示空白图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!