水晶报表中的图像显示 [英] Image display in a crystal report

查看:87
本文介绍了水晶报表中的图像显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是在Crystal报表中用于图像显示的代码.这不起作用.

请对此进行回复.

Following is code for image display in a crystal report. This is not working.

Please reply on this.

SQLQuery4 = " Select ImageS from tblForm14 where  " + query5;
                    SQLQuery4 = SQLQuery4.Substring(0, SQLQuery4.Length - 4);
                    SqlCommand cmd = new SqlCommand(SQLQuery4, Cn3);
                    string ss = (string)cmd.ExecuteScalar();
                    BoxObject Box1;
                   
                    PictureObject pct;
                    pct = cryRtp.ReportDefinition.Sections["Section3"].ReportObjects["Picture1"]as PictureObject; 
                 
                    //rpt.sections("Section1").reportobjects("picture1")=loadpicture("c:\test.bmp")

                    //pictureBox1.ImageLocation = @"D:/Rider/" + dt.Rows[0][17].ToString();
                    //Box1 = (BoxObject)cryRtp.ReportDefinition.Sections["Section3"].ReportObjects["Box1"];
                    DataTable dt = new DataTable();
                    DataRow drow;
                    dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
                    drow = dt.NewRow();
                    FileStream fs;
                    BinaryReader br;
                    if (File.Exists(@"D:/Rider/" + ss))
                    {
               
                        fs = new FileStream(@"D:/Rider/" + ss, FileMode.Open); 
                    }
                    else
                    {
                        fs = new FileStream(@"D:/Rider/" + "NoPhoto.jpg", FileMode.Open);
                    }
                    br = new BinaryReader(fs);
                    byte[] imgbyte = new byte[fs.Length + 1]; 
                    imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
                    drow[0] = imgbyte;
                    
                    dt.Rows.Add(drow);
                    br.Close();
                    fs.Close();
                  
                    cryRtp.SetDataSource(dt);
                     crystalReportViewer1.ReportSource = cryRtp;
                
                 cryRtp.SetDataSource(D8);
                 cryRtp.SetDataSource(D9);
                 cryRtp.SetDataSource(d10);
                    crystalReportViewer1.ReportSource = cryRtp;

}

推荐答案

执行以下步骤即可在Chrystal报表中查看图像.

1.在设计时在水晶报表中插入一个图片框.
2.在数据集中设置一个列名称Photo
3.将此列属性数据类型设置为System.Byte[],在设计时为空白.仅在设计时从Field Explorer添加链接.
4.在cs文件中,还添加一列名为Photo的数据类型为System.Byte[]的列,该列已填充​​已绑定到您的Chrystal报表的数据集.

fallow these steps to view an image in Chrystal report.

1.Insert a picture box in crystal report at design time.
2.In data set a column name Photo
3.Sett this column properties data type to System.Byte[] which have blank at design time.its only for add link at design time from field explorer.
4.In cs file add also a column named Photo with data type System.Byte[] which have fill the data set which have bind to your Chrystal report.

ds.Tables[0].Columns.Add("Photo", System.Type.GetType("System.Byte[]"));

                FileStream fs = new FileStream(PHotoPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] Image = new byte[fs.Length];
                fs.Read(Image, 0, Convert.ToInt32(fs.Length));
                fs.Close();
                ds.Tables[0].Rows[0]["Photo"] = Image;



5,最后设置您通常要做的数据源.

背后的逻辑是我们在记录中添加一个数据集列.



5.Finally set your data sources u do usually.

Logic behind is that we add a data set column with our record.


您好,如果您将图像存储在表中,则从项目中添加一个数据表-添加新项目-数据-接受方式默认dataset1.xsd并在数据表上单击鼠标右键,添加名称为image的列,在图像列上单击鼠标右键,然后在列的属性上单击,更改数据类型System.Byte [],然后添加水晶报表.选择数据时,单击接受默认设置.在项目数据上-ADO.net DataSet选择要添加的DataTable.

将您添加的图像列拖到datatable中,因为添加水晶报表时该列未显示在datatable1中.单击下一步-完成并从field Explorer中拖动图像列-datatable1



将水晶报表绑定到您的按钮上,单击并编写以下代码
Hello are you store image in table if yes then add a data table from project - add new item - data - accept by default dataset1.xsd and Right click on datatable add collumn having name image right click on image column and click on property of column change the datatype System.Byte[] then add your add a crystal report Click on accept default setting when you choose data Click on Project Data - ADO.net DataSet Select the DataTable which you add.

Drage the image column add by you in datatable, because the column is not display in datatable1 at the time you add crystal report click on next button - finish and drag the image column from field explorer - datatable1



bind the crystal report on your button click and write the below code
private void button1_Click(object sender, EventArgs e)
       {
           CrystalReport1 crRpt = new CrystalReport1();
           SqlDataAdapter adp = new SqlDataAdapter("select picture as image from Table1", con);
           DataSet1 ds = new DataSet1();
           adp.Fill(ds, "Table1");
           crRpt.SetDataSource(ds.Tables[1]);
           crystalReportViewer1.ReportSource = crRpt;
           crystalReportViewer1.Refresh();
       }


这篇关于水晶报表中的图像显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆