Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PreviewControl UIElement to Image

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jinsol.kim
959 Views, 2 Replies

PreviewControl UIElement to Image

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? 

 

 

MultipleViews.png

 

2 REPLIES 2
Message 2 of 3
akira.kudo
in reply to: jinsol.kim

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.





Akira Kudo

Developer Technical Services

Autodesk Developer Network


Message 3 of 3
dklasnic
in reply to: akira.kudo

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. 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community