欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

Windows Phone截取当前屏幕保存图像的代码,phone截取

来源: 开发者 投稿于  被查看 25595 次 评论:203

Windows Phone截取当前屏幕保存图像的代码,phone截取


 

导入以下命名空间:

using System.Windows.Media.Imaging;
using System.IO;
using Microsoft.Xna.Framework.Media;

 

全部代码如下:

public void CaptureScreen(object sender, EventArgs e)
{
    WriteableBitmap bmp = new WriteableBitmap(480, 800);
    bmp.Render(App.Current.RootVisual, null);
    bmp.Invalidate();

    MemoryStream stream = new MemoryStream();
    bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 80);
    stream.Seek(0, SeekOrigin.Begin);

    MediaLibrary library = new MediaLibrary();
    string fileName = "ScreenShot_" + DateTime.Now.ToString("yyyy-mm-dd_hh:mm:ss");
    library.SavePicture(fileName, stream);
    stream.Close();

    Dispatcher.BeginInvoke(() =>
    {
        PictureCollection picCollection = library.Pictures;
        foreach (Picture item in picCollection)
        {
            if (item != null)
            {
                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(item.GetImage());
            }
        }
    });
}

 

转自:http://terryblog.blog.51cto.com/1764499/551752/

相关频道:

用户评论