Reputation:
How Can I change an Image (its an OLE Object) in a Crystal report using C#?
Upvotes: 1
Views: 3524
Reputation: 3118
you can add CRAXDRT.dll and CrystalDecisions.Shared.dll to your references then you can use this code:
CRAXDRT.Report report2 = new CRAXDRT.Report();
CRAXDRT.Application app2 = new CRAXDRT.Application();
report2 = app2.OpenReport("YourReportName.rpt", OpenReportMethod.OpenReportByDefault);
for (int i = 1; i < report2.Sections.Count + 1; i++)
{
for (int j = 1; j < report2.Sections[i].ReportObjects.Count + 1; j++)
{
try
{
CRAXDRT.OleObject to2 = (CRAXDRT.OleObject)report2.Sections[i].ReportObjects[j];
CRAXDRT.OleObject to3 = report2.Sections[i].AddPictureObject("NewOleName.bmp", to2.Left, to2.Top);
to3.Height = to2.Height;
to3.Width = to2.Width;
report2.Sections[i].DeleteObject(to2);
}
catch (Exception) { }
}
}
Upvotes: 2
Reputation: 16603
Suppose you have your image in a Bitmap object,
save it to MemoryStream in Bitmap format,
Create a DataSource, create DataTable in it with 1 DataColumn with type of byte array
MemoryStream ms; //contains saved bitmap~!!!
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("img", typeof(Byte[])));
DataRow row = dt.NewRow();
row["img"] = ms.ToArray();
also have the report (or subreport of your report) bound to DataSource with schema as above insert Image object bound to the "img" column to report
Upvotes: 1