水晶报表随笔(一)在winform下加载本地图片

来源:互联网 发布:手机淘宝怎么付款 编辑:程序博客网 时间:2024/04/30 20:46

本人使用的环境是vs2008sp1、vs2008自带水晶报表

 

我用的文件列表
CrystalReport1.rpt
DataSet1.xsd
Form1.cs
其中
DataSet1只有一个名叫DataTable1表,有两个字段,图片:System.Byte[],路径:System.String
下面是我的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;
using System.IO;

namespace CrystalReportsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            FileStream fLogo = new FileStream(@"D:/Backup/我的文档/My Pictures/AA.jpg", FileMode.Open, FileAccess.Read);
            BinaryReader bReader = new BinaryReader(fLogo);
            byte[] bt = bReader.ReadBytes((int)bReader.BaseStream.Length);

            DataSet1 ds = new DataSet1();
           
            bReader.Close();
            fLogo.Close();

            ds.DataTable1.AddDataTable1Row(bt, @"C:/WINDOWS/Web/exclam.gif");

            ReportDocument myReport = new ReportDocument();
            string reportPath = @"D:/test/WindowsFormsCImge/CrystalReportsApplication1/crystalreport1.rpt";
            myReport.Load(reportPath);

            //绑定数据集,注意,一个报表用一个数据集。
            myReport.SetDataSource(ds.Tables["DataTable1"]);
            crystalReportViewer1.ReportSource = myReport;
            crystalReportViewer1.RefreshReport();
           
        }
    }
}

 

水晶报表支持的图片的格式有:jpg、bmp,不支持gif。