CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Handling snapshot of scrollable content using Silverlight's WriteableBitmap

819 Views
Copy Code Show/Hide Line Numbers
   1:  public static void ExportToJpeg() {
   2:      prepare(true);
   3:      SaveFileDialog saveDialog = new SaveFileDialog
   4:      {
   5:          Filter = "JPEG Files (*.jpeg)|*.jpeg",
   6:          DefaultExt = ".jpeg",
   7:      };
   8:      if ((bool)saveDialog.ShowDialog()) {
   9:          using (Stream fileStream = saveDialog.OpenFile()) {
  10:              WriteableBitmap bitmap = new WriteableBitmap(containerPanel, null);
  11:              if (bitmap != null) saveToJpegFile(bitmap, fileStream);
  12:          }
  13:      }
  14:      prepare(false);
  15:  }
  16:   
  17:  private static void prepare(bool imageExport) {
  18:      scrollViewer.VerticalScrollBarVisibility = imageExport ? 
  19:  ScrollBarVisibility.Hidden : ScrollBarVisibility.Visible;
  20:      bool hasScroll = scrollViewer.ViewportHeight < scrollViewer.ExtentHeight;
  21:      if (!hasScroll) return;
  22:      double scrollViewerHeight;
  23:      string pluginHeight;
  24:      if (imageExport) {
  25:          previousHeight = scrollViewer.ViewportHeight;
  26:          double heightDifference = scrollViewer.ExtentHeight - previousHeight;
  27:          double pluginActualHeight = App.Current.Host.Content.ActualHeight;
  28:          scrollViewerHeight = scrollViewer.ExtentHeight;
  29:          pluginHeight = String.Format("{0}px", pluginActualHeight + heightDifference);
  30:      } else {
  31:          scrollViewerHeight = previousHeight;
  32:          pluginHeight = "100%";
  33:      }
  34:      scrollViewer.Height = scrollViewerHeight;
  35:      HtmlPage.Plugin.SetStyleAttribute("height", pluginHeight);
  36:      containerPanel.UpdateLayout();
  37:  }
by Danijel Stulic
  August 17, 2009 @ 5:18am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate