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

问题描述

以下是在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;

}

推荐答案

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.


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();
       }


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

09-09 19:39