I have tried as follows
BitmapSource bitmap;
bitmap = graphData.CreateScreenshot();
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
BitmapFrame outputFrame = BitmapFrame.Create(bitmap);
encoder.Frames.Add(outputFrame);
encoder.QualityLevel = 100;
FileStream stream = new FileStream("test.jpg", FileMode.Create);
encoder.Save(stream);
but I am not able to view the image. I can see following message:
Windows photo viewer can't open this picture because the picture is being edited in another program
What went wrong here?