Hello,
I've created a WPF window that will display two differnt Revit views from different documents using PreviewControl. As Revit doesn not support more than one preview contorl, I thought I could present one view by the preview control, and another view by the copied image from the UIElement, PreviewControl, instead of defining the preview control directly as a content.
In order to get an image of the rendered preview control, I tried to get RenderTargetBitmap and render with preview control, but it didn't work well.
----------------------------------------------------------------------------------------------------------------------------------------------------
ContentPresenter item=previewcontrol.Content as ContentPresenter;
RenderTargetBitMap bitmap=new RenderTargetBitmap(width, height, 100,100, PixelFormats.Default);
DrawingVisual drawingVisual=new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
VisualBrush visualBrush = new VisualBrush(item);
drawingContext.DrawRectangle(visualBrush, null, new Rect(new Point(), new Size(width, height)));
}
bitmap.Render(item);
Image.Source=bitmap;
--------------------------------------------------------------------------------------------------------------------------------------------------
Can you tell me the way of acceess to any of visual objects from PreviewControl?
Solved! Go to Solution.
Solved by akira.kudo. Go to Solution.
Hi
I think you are hitting an issue that is called "Cannot render content of PreviewControl into a bitmap using RenderTargetBitmap".
One workaround here is to export the view as image with Revit API - Document.ExportImage method.
So there is a ssample in the sdk as below.
C:\Revit 2014 SDK\Samples\ImportExport\CS\Export\ExportIMGOptionsForm.cs(227): m_exportData.ActiveDocument.ExportImage(m_exportOptions);
Please let me know, if it does not work for you.
I hope this helps.
Hi,
I got "Exception UIView = 'control.UIView' threw an exception of type 'Autodesk.Revit.Exceptions.InternalException'." when initializing PrevievControl object. What is the problem?
Thanks.