none
WPF 画图 RRS feed

答案

  •   private void save_Click(object sender, RoutedEventArgs e)
      {
       SaveFileDialog sfd = new SaveFileDialog();
       sfd.Filter = "Png Files(*.png)|*.png";
    
       Nullable<bool> result = sfd.ShowDialog();
       string fileName = "";
    
       if (result == true)
       {
        fileName = sfd.FileName;
        Size size = usercontrol.RenderSize;
        RenderTargetBitmap rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
        rtb.Render(usercontrol);
        PngBitmapEncoder png = new PngBitmapEncoder();
        png.Frames.Add(BitmapFrame.Create(rtb));
        using (Stream stm = File.Create(fileName))
        {
         png.Save(stm);
        }
       }
      }
    


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年7月22日 3:38
    版主

全部回复

  •   private void save_Click(object sender, RoutedEventArgs e)
      {
       SaveFileDialog sfd = new SaveFileDialog();
       sfd.Filter = "Png Files(*.png)|*.png";
    
       Nullable<bool> result = sfd.ShowDialog();
       string fileName = "";
    
       if (result == true)
       {
        fileName = sfd.FileName;
        Size size = usercontrol.RenderSize;
        RenderTargetBitmap rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
        rtb.Render(usercontrol);
        PngBitmapEncoder png = new PngBitmapEncoder();
        png.Frames.Add(BitmapFrame.Create(rtb));
        using (Stream stm = File.Create(fileName))
        {
         png.Save(stm);
        }
       }
      }
    


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年7月22日 3:38
    版主
  • 非常感谢

    2011年7月23日 0:50