2013-10-28 2 views
1

RenderTargetBitmap을 사용하여 XAML을 쓰지 않고 UserControl을 비트 맵에 렌더링하고 싶습니다. 이 작업을 수행 할 때 빈 이미지가 나타나면 중요한 단계를 놓치고 있습니까?XAML 대신 코드로 UserControl 렌더링

var width = VideoContainer.ActualWidth; 
var height = VideoContainer.ActualHeight; 

vfoc.Measure(new Size(width, height)); 
vfoc.Arrange(new Rect(0, 0, width, height)); 
vfoc.InvalidateVisual(); 
:
ValTool.Controls.VideoFisheyeOverlayControl vfoc = new Controls.VideoFisheyeOverlayControl(); 
vfoc.Width = (int)this.VideoContainer.ActualWidth; 
vfoc.Height = (int)this.VideoContainer.ActualHeight; 
vfoc.FieldsOfView=this.FieldsOfView; 
vfoc.CountLines = this.CountLines; 

vfoc.UpdateLayout(); 
vfoc.InvalidateVisual(); 

RenderTargetBitmap visual = new RenderTargetBitmap((int)this.VideoContainer.ActualWidth, (int)this.VideoContainer.ActualHeight, 96, 96, PixelFormats.Pbgra32); 
visual.Render(vfoc); 
var finalImage = BitmapFrame.Create(visual); 
// Encoding the RenderBitmapTarget as a PNG file. 
PngBitmapEncoder png = new PngBitmapEncoder(); 
png.Frames.Add(BitmapFrame.Create(finalImage)); 
using (Stream stm = File.Create(@"new.png")) 
{ 
    png.Save(stm); 
} 

답변

3

대신에 UpdateLayout의 당신은 레이아웃이 완료 얻을 MeasureArrange를 호출해야