private void AppendImage(HtmlNode node, Paragraph paragraph) { //AppendLineBreak(node, paragraph, null, false); InlineUIContainer inlineContainer = new InlineUIContainer(); Image image = new Image(); image.Margin = new Thickness(0, 0, 0, 10); image.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; var source = node.Attributes["src"]; if (source != null) { using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { BitmapImage bitmapImage; var imageFilePath = ImagesStorageManager.GetImagePath(source.Value, BookmarkViewModel.BookmarkId); if (!string.IsNullOrEmpty(imageFilePath)) { using (var imageStream = isoStore.OpenFile(imageFilePath, FileMode.Open, FileAccess.Read)) { bitmapImage = new BitmapImage(); bitmapImage.SetSource(imageStream); } bitmapImage.ImageOpened += delegate { double bitmapWidth = bitmapImage.PixelWidth; double actualWidth = _currentTextBox.ActualWidth; image.Source = bitmapImage; if (bitmapWidth < actualWidth) { image.Width = bitmapWidth; } }; image.Source = bitmapImage; inlineContainer.Child = image; image.Stretch = Stretch.Uniform; } } paragraph.Inlines.Add(inlineContainer); } RenderChildren(node, paragraph, null); //AppendLineBreak(node, paragraph, null, false); }
private static void ProcessBodyImages(long bookmarkId, string html) { var document = new HtmlDocument(); document.LoadHtml(html); var body = document.DocumentNode; var imageNodes = body.SelectNodes("//img"); if (imageNodes != null) { ImagesStorageManager.ClearImageCache(bookmarkId); foreach (var imageNode in imageNodes) { var sourceAttribute = imageNode.Attributes["src"]; ImagesStorageManager.AddImage(bookmarkId, sourceAttribute.Value); } } }
private void AppendImage(HtmlNode node, Paragraph paragraph) { //AppendLineBreak(node, paragraph, null, false); //InlineUIContainer inlineContainer = new InlineUIContainer(); //Image image = new Image(); //image.Margin = new Thickness(0, 20, 0, 20); //image.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; //if (node.Attributes["src"] != null) //{ // BitmapImage bitmap = new BitmapImage(new Uri(node.Attributes["src"].Value)); // bitmap.CreateOptions = BitmapCreateOptions.None; // bitmap.ImageOpened += delegate // { // double bitmapWidth = bitmap.PixelWidth; // double actualWidth = _currentRichTextBox.ActualWidth; // image.Source = bitmap; // if (bitmapWidth < actualWidth) // { // image.Width = bitmapWidth; // } // }; //} //inlineContainer.Child = image; //image.Stretch = Stretch.Uniform; //paragraph.Inlines.Add(inlineContainer); //AppendChildren(node, paragraph, null); //AppendLineBreak(node, paragraph, null, false); AppendLineBreak(node, paragraph, null, false); InlineUIContainer inlineContainer = new InlineUIContainer(); Image image = new Image(); image.Margin = new Thickness(0, 0, 0, 10); image.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; var source = node.Attributes["src"]; if (source != null) { BitmapImage bitmapImage; bitmapImage = ImagesStorageManager.GetImage(source.Value, BookmarkViewModel.BookmarkId); if (bitmapImage != null) { image.Source = bitmapImage; //if (writableImage.PixelWidth < _currentRichTextBox.ActualWidth) //{ // image.Width = writableImage.PixelWidth; //} } else { bitmapImage = new BitmapImage(new Uri(node.Attributes["src"].Value)); bitmapImage.CreateOptions = BitmapCreateOptions.None; } bitmapImage.ImageOpened += delegate { double bitmapWidth = bitmapImage.PixelWidth; double actualWidth = _currentRichTextBox.ActualWidth; image.Source = bitmapImage; if (bitmapWidth < actualWidth) { image.Width = bitmapWidth; } }; } inlineContainer.Child = image; image.Stretch = Stretch.Uniform; paragraph.Inlines.Add(inlineContainer); AppendChildren(node, paragraph, null); AppendLineBreak(node, paragraph, null, false); }