5

I need to take screenshots using Windows Phone. I don't want to take screenshots using the emulator and power+start button manually. Is there anything that can be done programmatically ?

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300
Ramesh
  • 415
  • 7
  • 16

1 Answers1

8

Here is the code:

private void ApplicationBarScreenshotButton_Click(object sender, EventArgs e)
{
    var fileName = String.Format("MyImage_{0:}.jpg", DateTime.Now.Ticks);
    WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
    bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
    bmpCurrentScreenImage.Invalidate();
    SaveToMediaLibrary(bmpCurrentScreenImage, fileName, 100);
    MessageBox.Show("Captured image " + fileName + " Saved Sucessfully", "WP Capture Screen", MessageBoxButton.OK);

    currentFileName = fileName;
}

public void SaveToMediaLibrary(WriteableBitmap bitmap, string name, int quality)
{
    using (var stream = new MemoryStream())
    {
        // Save the picture to the Windows Phone media library.
        bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
        stream.Seek(0, SeekOrigin.Begin);
        new MediaLibrary().SavePicture(name, stream);
    }
}

When you click on the AppBar button it will take the screenshot and Save the picture to the Windows Phone media library

poke
  • 369,085
  • 72
  • 557
  • 602
Rashad Valliyengal
  • 3,132
  • 1
  • 25
  • 39
  • Nice it's working Fine , How i take a screenshot programatically when Some Message Box is Popup or Some Keypad Popup, At that Time I like to Take a screen Short , is that Possible – Satti Dec 23 '13 at 16:54
  • Thanx, even the virtual keyboard popup you can do the same operation to take the screenshot by taping the ApplicationBarIconButton. But if you want to take screenshot when any MessageBox popup you need to press Widnows Home and Power button simultaneously. i didnt try any alternatives. – Rashad Valliyengal Dec 24 '13 at 04:54