1
public
void
CaptureScreen(
object
sender, EventArgs e)
2
{
3
WriteableBitmap bmp
=
new
WriteableBitmap(
480
,
800
);
4
bmp.Render(App.Current.RootVisual,
null
);
5
bmp.Invalidate();
6
7
MemoryStream stream
=
new
MemoryStream();
8
bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight,
0
,
80
);
9
stream.Seek(
0
, SeekOrigin.Begin);
10
11
MediaLibrary library
=
new
MediaLibrary();
12
string
fileName
=
"
ScreenShot_
"
+
DateTime.Now.ToString(
"
yyyy-mm-dd_hh:mm:ss
"
);
13
library.SavePicture(fileName, stream);
14
stream.Close();
15
16
17
Dispatcher.BeginInvoke(()
=>
18
{
19
PictureCollection picCollection
=
library.Pictures;
20
foreach
(Picture item
in
picCollection)
21
{
22
if
(item
!=
null
)
23
{
24
BitmapImage bitmap
=
new
BitmapImage();
25
bitmap.SetSource(item.GetImage());
26
ScreenShot.Source
=
bitmap;
27
PicName.Text
=
"
圖片名稱 :
"
+
item.Name;
28
}
29
30
}
31
});
32
33
34