WebPictureBox.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using FastReport.Dialog;
  2. using System.Drawing;
  3. using System.IO;
  4. namespace FastReport.Web
  5. {
  6. public partial class Dialog
  7. {
  8. private string GetPictureBoxHtml(PictureBoxControl control)
  9. {
  10. return $"<div style=\"{GetPictureBoxStyle(control)}\"></div>";
  11. }
  12. private string GetPictureBoxStyle(PictureBoxControl control)
  13. {
  14. return $"{GetControlPosition(control)} {GetControlAlign(control)} {GetPictureBoxURL(control.Image)} padding:0;margin:0;";
  15. }
  16. private string GetPictureBoxURL(Image image)
  17. {
  18. #if !WASM
  19. int hash = image.GetHashCode();
  20. if (!_webReport.PictureCache.ContainsKey(hash.ToString()))
  21. {
  22. using (MemoryStream picStream = new MemoryStream())
  23. {
  24. image.Save(picStream, image.RawFormat);
  25. byte[] imageArray = new byte[picStream.Length];
  26. picStream.Position = 0;
  27. picStream.Read(imageArray, 0, (int)picStream.Length);
  28. _webReport.PictureCache.Add(hash.ToString(), imageArray);
  29. }
  30. }
  31. string url = WebUtils.ToUrl(_webReport.template_ROUTE_BASE_PATH, $"preview.getPicture?");
  32. return $"background: url('{url}reportId={_webReport.ID}&pictureId={hash}') no-repeat !important;-webkit-print-color-adjust:exact;";
  33. #else
  34. return "";
  35. #endif
  36. }
  37. }
  38. }