Usage:
Code Snippet
- dlg.FileName = "Image"; // Default file name
- dlg.DefaultExt = ".png"; // Default file extension
- dlg.Filter = "PNG File (.png)|*.png"; // Filter files by extension
- // Show save file dialog box
- Nullable<bool> result = dlg.ShowDialog();
- // Process save file dialog box results
- if (result == true)
- {
- // Save document
- string filename = dlg.FileName;
- SaveCanvasToFile(this, DrawingCanvas, 96, filename);
- }
End of Code Snippet
Code Snippet
- public static void SaveCanvasToFile(Window window, Canvas canvas, int dpi, string filename)
- {
- canvas.Measure(size);
- //canvas.Arrange(new Rect(size));
- (int)window.Width, //width
- (int)window.Height, //height
- dpi, //dpi x
- dpi, //dpi y
- PixelFormats.Pbgra32 // pixelformat
- );
- rtb.Render(canvas);
- SaveRTBAsPNGBMP(rtb, filename);
- }
- public static void SaveWindowToFile(Window window, int dpi, string filename)
- {
- (int)window.Width, //width
- (int)window.Width, //height
- dpi, //dpi x
- dpi, //dpi y
- PixelFormats.Pbgra32 // pixelformat
- );
- rtb.Render(window);
- SaveRTBAsPNGBMP(rtb, filename);
- }
- private static void SaveRTBAsPNGBMP(RenderTargetBitmap bmp, string filename)
- {
- enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bmp));
- using (var stm = System.IO.File.Create(filename))
- {
- enc.Save(stm);
- }
- }
End of Code Snippet
No comments:
Post a Comment