So I have a DrawingSurfaceBackgroundGrid inside of a PhoneApplicationPage, in my WP8 app; and I would like to take a screenshot. As far as I can tell (from google), there isn't a call to simply "take a screenshot". What people are doing is using a WriteableBitmap, like this:
WriteableBitmap wbmp = new WriteableBitmap(test, null);
wbmp.SaveJpeg(isoStream2, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
I have tried test as both the DrawingSurfaceBackgroundGrid, and the PhoneApplicationPage. Neither of these are working for me. Could it have something to do with the fact that I am rendering everything using RenderTargets and pixel shaders (in SharpDX)? I just get a black image. Here is the code to save the image:
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream isoStream2 = new IsolatedStorageFileStream("new.jpg", FileMode.OpenOrCreate, isoStore))
{
WriteableBitmap wbmp = new WriteableBitmap(test, null);
wbmp.SaveJpeg(isoStream2, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
}
But like I said, it just creates a black image.
Any ideas?
Tried your code as is with the exception of changing "test" to the name of the root grid, in my app x:Name="LayoutRoot"
, and works fine! Just replace test with the element you want to capture, the root-grid name for whole page or sub element name for just that element.
BTW thanks for the code, one more to squirrel away.
I am using the code below. Though it is saving to the Media Gallery.
WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
bmpCurrentScreenImage.Invalidate();
using (var stream = new MemoryStream())
{
// Save the picture to the Windows Phone media library.
bmpCurrentScreenImage.SaveJpeg(stream, bmpCurrentScreenImage.PixelWidth, bmpCurrentScreenImage.PixelHeight, 0, quality);
stream.Seek(0, SeekOrigin.Begin);
var picture = new MediaLibrary().SavePicture(name, stream);
return picture.GetPath();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.