Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
303 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...