I want to create a software user control in a DLL so that I can save it as a PNG file later. This is usually not a problem with PngBitmapEncoder and RenderTargetBitmap.
These are my questions:
- How to instantiate a control? Just with a new operator?
- Do I need to create an instance in a separate thread?
- How to get a control to update all its children and display it again?
This is my code to create a user control and save it as a PNG file (LetterFrequency is a user control):
[STAThread]
static void Main(string[] args)
{
LetterFrequency let = new LetterFrequency();
let.Width = 600;
let.Height = 400;
let.Background = Brushes.White;
let.Measure(new Size(let.Width, let.Height));
let.Arrange(new Rect(new Size(let.Width, let.Height)));
let.UpdateLayout();
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)let.Width, (int)let.Height, 96d, 96d, PixelFormats.Pbgra32);
bitmap.Render(let);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(bitmap));
using (Stream stm = File.Create("test.png"))
{
png.Save(stm);
}
}
, PNG , , XAML, , XAML Designer, . png , ? ? , /, ?
, , PNG WPF .
, PNG bin/Debug exe-: http://www.file-upload.net/download-1904406/ChartRenderBitmap.zip.html
, !
!
rbee