2013-11-29 56 views

回答

7

下面是代碼:

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); 
     new MediaLibrary().SavePicture(name, stream); 
    } 
} 

當你點擊AppBar按鈕,它會採取截圖和圖片保存到Windows Phone媒體庫

+0

尼斯它的正常工作,我該怎麼坐當某些消息框彈出或某些鍵盤彈出窗口時,以編程方式進行截圖,那時候我喜歡以一個屏幕Short,可能是 –

+0

Thanx,即使是虛擬鍵盤彈出窗口也可以通過錄制ApplicationBarIconButton來執行相同的操作。但是,如果您想在任何MessageBox彈出窗口中進行截圖,則需要同時按下Widnows Home和Power按鈕。我沒有嘗試任何替代品。 –

相關問題