2016-09-20 49 views
1

我可以「導入」圖像(拾取文件)並將其包裝在邊框中的inlineUIContainer中。
- 但是,當我保存文檔時,圖像消失(非常短的文件)。RichTextBox中的圖像(FlowDocument)

或者我可以從剪貼板粘貼(無邊框封裝)。
- 那麼它得到保存爲文件 - 但我有在顯示無法控制......

什麼是在FlowDocument的導入圖像(從文件),並保持實際的位圖
的正確方法,所以它可以與RichText的其餘部分一起保存?

編輯:
我的問題似乎是,該圖像表示(在XAML)與URI
- 而不是實際的位圖 - 所以如何導入/正確地嵌入了嗎?
這是我的導入代碼:

string fileName = openFileDialog.FileName; 
BitmapImage bitmap = new BitmapImage(new Uri(fileName, UriKind.Absolute)); 

Image image = new Image(); 
image.Source = bitmap; 
image.Width = bitmap.Width; 
image.Height = bitmap.Height; 

Border border = new Border(); 
border.Background = Brushes.Blue; 
border.BorderBrush = Brushes.Red; 
border.BorderThickness = new Thickness(10); 
border.Margin = new Thickness(10); 
border.Padding = new Thickness(10); 

border.Child = image; 

InlineUIContainer box = new InlineUIContainer(border, rt.CaretPosition); 
+0

選中此http://stackoverflow.com/questions/14895745/saving -richtextbox-flowdocument-to-image – Techidiot

+0

感謝Techidiot,但那根本不是。我只想將圖像保存爲「內部」 - 不將圖像導出爲圖像。 – T4NK3R

+0

爲什麼每一件小事都是WPF中黑客和變通辦法的噩夢?!?我現在試圖通過在內部使用剪貼板作弊,但這也非常困難,並且不允許透明(png和gif),所以完全放棄了WPF ... – T4NK3R

回答

0

嘗試在Viewbox,而不是像這樣一個邊框封裝圖片:

string fileName = openFileDialog.FileName; 
BitmapImage bitmap = new BitmapImage(new Uri(fileName, UriKind.Absolute)); 

BlockUIContainer blockUI = new BlockUIContainer(); 
Image img = new Image(); 
img.Source = bitmap; 
Viewbox vb = new Viewbox(); 
vb.StretchDirection = StretchDirection.DownOnly; 
vb.Stretch = Stretch.Uniform; 
vb.HorizontalAlignment = HorizontalAlignment.Center; 
vb.VerticalAlignment = VerticalAlignment.Center; 
vb.Child = img; 
blockUI.Child = vb; 

rt.Document.Blocks.Add(blockUI); 
相關問題