Exemplo n.º 1
0
        /// <summary>
        /// Fix the raw html by replacing bridge object properties calls with path to file with the data returned from the property.
        /// </summary>
        /// <returns>fixed html</returns>
        private string GetFixedHtml()
        {
            var html = GetHtmlEditorText();

            html = Regex.Replace(html, @"src=\""(\w.*?)\""", match =>
            {
                var img = HtmlRenderingHelper.TryLoadResourceImage(match.Groups[1].Value);
                if (img != null)
                {
                    var tmpFile = Path.GetTempFileName();
                    var encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(img));
                    using (FileStream stream = new FileStream(tmpFile, FileMode.Create))
                        encoder.Save(stream);
                    return(string.Format("src=\"{0}\"", tmpFile));
                }
                return(match.Value);
            }, RegexOptions.IgnoreCase);

            html = Regex.Replace(html, @"href=\""(\w.*?)\""", match =>
            {
                var stylesheet = DemoUtils.GetStylesheet(match.Groups[1].Value);
                if (stylesheet != null)
                {
                    var tmpFile = Path.GetTempFileName();
                    File.WriteAllText(tmpFile, stylesheet);
                    return(string.Format("href=\"{0}\"", tmpFile));
                }
                return(match.Value);
            }, RegexOptions.IgnoreCase);

            return(html);
        }
        private void OnSaveToFile_click(object sender, RoutedEventArgs e)
        {
            var saveDialog = new SaveFileDialog();

            saveDialog.Filter     = "Images|*.png;*.bmp;*.jpg;*.tif;*.gif;*.wmp;";
            saveDialog.FileName   = "image";
            saveDialog.DefaultExt = ".png";

            var dialogResult = saveDialog.ShowDialog(this);

            if (dialogResult.GetValueOrDefault())
            {
                var encoder = HtmlRenderingHelper.GetBitmapEncoder(Path.GetExtension(saveDialog.FileName));
                encoder.Frames.Add(_generatedImage);
                using (FileStream stream = new FileStream(saveDialog.FileName, FileMode.OpenOrCreate))
                    encoder.Save(stream);
            }
        }
Exemplo n.º 3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var imageStream = typeof(Resources).Assembly.GetManifestResourceStream("DA.HtmlRenderer.Demo.Common.Resources." + parameter + ".png");

            return(HtmlRenderingHelper.ImageFromStream(imageStream));
        }