码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2014-12-23 19:04:30      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

 

导入以下命名空间:

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/

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

标签:

原文地址:http://www.cnblogs.com/wzwyc/p/4180631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!