Ich habe einen Bericht, wo es ein statisches Bild ist, aber ich muss das Bild dynamisch laden.
geprüft Bereits this, this, this und this
Alles, was ich ohne Erfolg versucht. Ich brauche einen Beispielcode.
Irgendwelche Vorschläge?Crystal Report laden Bild (Bytes []) zur Laufzeit mit C#
-1
A
Antwort
0
Um Bilder dynamisch zu laden, habe ich eine neue Klasse/ein neues Modell ImageModel erstellt.
public class ImageModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Byte[] ImageBytes { get; set; }
}
Diese Klasse ein Feld Bild, es lädt das Bild genannt hat. Der nächste Schritt ist das Hinzufügen von ImageBytes Feld zum Bericht.
Mithilfe der Crystal Report-Benutzeroberfläche mithilfe des Feld-Explorers wurde eine neue Verbindung erstellt. In dieser neuen Verbindung habe ich meine ImageModel Klasse als Modell verwendet. Durch Hinzufügen der ImageBytes Feld, bemerkte ich, dass Crystal Reports einen Typ crBlobFieldObject Objekt hinzugefügt.
das Bild zu laden war notwendig, den folgenden Code zu machen:
public Byte[] GetImageBytes(string image_name)
{
Byte[] bytes = null;
if (!string.IsNullOrEmpty(image_name))
{
string app_path = ((System.Web.HttpRequestWrapper)this.Request)
.PhysicalApplicationPath;
app_path += "Content\\images\\";
string full_path = app_path + image_name;
//
if (System.IO.File.Exists(full_path))
{
FileStream fs = new FileStream(full_path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
bytes = br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));
}
}
return bytes;
}
Der Haupt Code wie folgt aussieht:
public JsonResult GenerateCrystalReportImage()
{
List<ImageModel> list_image = new List<ImageModel>();
//
ImageModel imageone = new ImageModel();
imageone.Id = 1;
imageone.Name = "Image name one";
imageone.Description = "This is a image description one";
imageone.Image = GetImageBytes("imageone.png");
list_image.Add(imageone);
//
ImageModel imagetwo = new ImageModel();
imagetwo.Id = 2;
imagetwo.Name = "Image name two";
imagetwo.Description = "This is a image description two";
imagetwo.Image = GetImageBytes("imagetwo.png");
list_image.Add(imagetwo);
//
ReportDocument rp = new ReportDocument();
rp.Load(System.Web.HttpContext.Current.Server.MapPath("~/Reports/") + "Test.rpt");
rp.SetDataSource(list_image);
rp.ExportToHttpResponse(ExportFormatType.PortableDocFormat,
System.Web.HttpContext.Current.Response,
false,
"image_list_" + DateTime.Now);
rp.Close();
return Json(new
{
data = "ok",
results = 1,
success = true,
errors = String.Empty
}, JsonRequestBehavior.AllowGet);
}
Verwandte Themen
- 1. Dynamisch ein Bild in einem Crystal Report zur Laufzeit ändern
- 2. Einstellen der Crystal Report-Datenquelle zur Laufzeit
- 3. Crystal Report mit Objektdatensatz
- 4. Crystal Report + C# Datumsformat
- 5. Crystal Report fragt nach Passwort in C#?
- 6. Problem mit Crystal Report
- 7. Crystal Report -WhilePrintingRecords
- 8. Crystal Report xi + C# .net-Dokument laden Problem
- 9. Crystal Report wird nicht im Crystal Report Viewer angezeigt. WPF
- 10. Crystal Report fragen Datenbank Parameter Login C#
- 11. Crystal Report Korruption
- 12. Crystal Report in ASP.NET - Display-Bild
- 13. mit Crystal Report mit Azure
- 14. Ändern der XML-Datenquelle von Crystal Report
- 15. Crystal Report viwer Problem
- 16. Crystal Report Tutorial
- 17. C#, ASP.NET 3.5 - Code zur Laufzeit laden
- 18. Crystal Report Problem
- 19. Lastbericht faild mit Crystal Report
- 20. Mit Teilzeichenfolge in Crystal Report
- 21. Crystal Report hierarchische Gruppierung
- 22. Anrufsitzung im Crystal Report
- 23. Crystal Report grow horziontal
- 24. Crystal Report DateTime Konvertierung
- 25. Crystal Report Auswahl Formel
- 26. Crystal Report Chart Option in C#
- 27. Crystal Report Mehrere Abfragen
- 28. Crystal Report druckt nicht online
- 29. Crystal Report Dynamisches Parameterproblem
- 30. .Net laden Referenz zur Laufzeit