using System.Windows.Media.Imaging;
using System.IO;

private void SaveToImage(FrameworkElement ui, string fileName, int width, int height)
        {
            try
            {
                System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
                RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96d, 96d,
                PixelFormats.Pbgra32);
                bmp.Render(ui);
                BitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));
                encoder.Save(fs);
                fs.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

相关文章:

  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-06-16
  • 2021-11-17
  • 2021-12-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-03-19
  • 2021-06-24
  • 2021-12-18
  • 2021-04-10
相关资源
相似解决方案