Windows Phone 7中的屏幕截图

时间:2014-07-07 04:39:48

标签: windows-phone-7

任何人都可以请告诉我如何截取屏幕并将其以编程方式保存到Windows Phone 7中。我不想在MediaLibrary()中保存图像,但我想将其保存到文件夹中应用程序的根目录

1 个答案:

答案 0 :(得分:0)

此代码将帮助您针对AppBar按钮单击操作截取屏幕截图。但是,您必须修改代码以将屏幕截图保存到应用程序的根文件夹中。以下链接将为您提供帮助。

Save into local storage Data for Windows Phone

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);

                // Use Above link to store file into Root folder.
                //new MediaLibrary().SavePicture(name, stream);
            }
        }