WP7:从应用程序中截取屏幕截图

时间:2011-04-05 14:21:56

标签: c# .net windows-phone-7

如何从代码中截取屏幕截图?

5 个答案:

答案 0 :(得分:4)

使用WriteableBitmap从应用程序代码中截取应用程序的截图非常简单。 Laurent Bugnion在这里写得很好:http://geekswithblogs.net/lbugnion/archive/2010/12/28/taking-a-screenshot-from-within-a-silverlight-wp7-application.aspx

答案 1 :(得分:2)

检查here,它似乎可以在模拟器上使用。

答案 2 :(得分:2)

从Silverlight#WP7应用程序中截取屏幕截图。

public static void SaveToMediaLibrary(
FrameworkElement element, 
string title)
{
try
{
    var bmp = new WriteableBitmap(element, null);

    var ms = new MemoryStream();
    bmp.SaveJpeg(
        ms,
        (int)element.ActualWidth,
        (int)element.ActualHeight,
        0,
        100);
    ms.Seek(0, SeekOrigin.Begin);

    var lib = new MediaLibrary();
    var filePath = string.Format(title + ".jpg");
    lib.SavePicture(filePath, ms);

    MessageBox.Show(
        "Saved in your media library!",
        "Done",
        MessageBoxButton.OK);
}
catch
{
    MessageBox.Show(
        "There was an error. Please disconnect your phone from the computer before saving.",
        "Cannot save",
        MessageBoxButton.OK);
}}

答案 3 :(得分:1)

以下是如何从您的应用中截取屏幕截图中的截图,并将其保存到手机的图片库中。请注意,这不会捕获SysTray或AppBar:

WriteableBitmap w = new System.Windows.Media.Imaging.WriteableBitmap(this, null); // 'this' is your current page
WriteableBitmap w2 = new System.Windows.Media.Imaging.WriteableBitmap(480, 800);

// space for SysTray
for (int i = 0; i < 32; i++)
{
    for (int j = 0; j < 480; j++)
    {
        w2.Pixels[i * 480 + j] = -16777216; // black #ff000000
    }
}

// actual client area
for (int i = 32; i < 728; i++)
{
    for (int j = 0; j < 480; j++)
    {
        w2.Pixels[i * 480 + j] = w.Pixels[(i - 32) * 480 + j];
    }
}

// space for AppBar
for (int i = 728; i < 800; i++)
{
    for (int j = 0; j < 480; j++)
    {
        w2.Pixels[i * 480 + j] = -16777216; // black #ff000000
    }
}
MemoryStream ms = new MemoryStream();
w2.SaveJpeg(ms, 480, 800, 0, 100);
Microsoft.Xna.Framework.Media.MediaLibrary lib = new Microsoft.Xna.Framework.Media.MediaLibrary();
ms.Position = 0;
lib.SavePicture("screenshot", ms);

答案 4 :(得分:0)

你不能害怕。如果你想要截图,你需要在外面使用像剪切工具这样的东西。