Friday, February 1, 2013

ASP.NET/ActiveX/Silverlight Screen Capture

ASP.NET/ActiveX/Silverlight Screen Capture

I need a way to capture the screen within a web application in any way possible. Is there such a way without installing other tools like SnagIt? Can I use Win32 DllImports within an ActiveX component and do it that way?

Thanks in advance!

Answers & Comments...

Answer: 1

On the Silverlight forums they say its not possible with just Silverlight, because of Security.

I think it should be possible somehow, because the PrintDocument is basically doing the same....
See below where we point to the LayoutRoot to print.

In the links from that forum they are registering a DLL in the GAC and using that one to create the screen shot. Not very nice ;-)
http://forums.silverlight.net/forums/p/163378/367809.aspx

private void ButtonPrint_Click(object sender, System.Windows.RoutedEventArgs e) {     PrintDocument pd = new PrintDocument();     pd.PrintPage += OnPrintPage;     pd.Print("from Silverlight"); }  private void OnPrintPage(object s, PrintPageEventArgs args) {     args.PageVisual = LayoutRoot; } 
by : Peter Gfaderhttp://stackoverflow.com/users/35693

Answer: 2

With pure Silverlight code, both in browser and out of browser, it's not possible to capture an image of the screen (thankfully! That would be a huge privacy and security issue if a rogue website could capture your screen and send it to their web site).

By writing a browser plug-in (such as an ActiveX control, which would work only in IE), you could write the necessary Win32 code to take a screen shot. It would still require some heavy lifting to manage the image, uploading, file security, etc. You might be able to write the COM control in C#, but it would need to be placed in the GAC (thus signed, etc.).

There are other solutions that involve local native installation and a browser based Silverlight application, but all require an installation on the PC.

I'd suggest considering instead a simple, zero-install (or click-once), EXE that can be run from a PC that just takes a screen shot and uploads it/e-mails/etc.. That would involve far fewer hacks to make it work.

Note that Windows 7 has a new accessory, called the Snipping Tool that can take an image of the screen and e-mail it.

by : WiredPrairiehttp://stackoverflow.com/users/95190

Answer: 3

Here is some code that will take a screen shoot of your silverlight app. and then you can send it or what ever :-)

Just create a silverlight project (with normal mainpage etc. and replace with this.

works in both 3.0 and 4.0 (havent tried 2.0 and lower)

Hope i helps Regards ReLoad

.CS

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Data; using System.Windows.Media.Imaging;

namespace SilverlightApplication1 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); }

    private void UIelementShoot(object sender, 

RoutedEventArgs e) { theImageToSend.Source = new WriteableBitmap(elementToCapture, null); }

    private void ScreenShoot(object sender, 

RoutedEventArgs e) { theImageToSend.Source = new WriteableBitmap(LayoutRoot, null); }

    private void Button_Click(object sender, 

RoutedEventArgs e) {

    } } } 

XAML:

<UserControl     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:local="clr-namespace:SilverlightApplication1" x:Class="SilverlightApplication1.MainPage"     mc:Ignorable="d"     d:DesignHeight="300" d:DesignWidth="400">      <Grid x:Name="LayoutRoot" Background="White" Width="400" Height="300" >         <Image x:Name="theImageToSend" Margin="191,56,44,103" d:LayoutOverrides="HorizontalAlignment"/>         <TextBox x:Name="elementToCapture" Margin="37,56,0,130" TextWrapping="Wrap" Text="TextBox" Width="124" HorizontalAlignment="Left" d:LayoutOverrides="Width"/>         <Button Content="Make ScreenShoot" HorizontalAlignment="Right" Margin="0,0,44,26" VerticalAlignment="Bottom" Width="139" Click="ScreenShoot"/>         <Button Content="Make TextBox Shoot" HorizontalAlignment="Left" Margin="61,0,0,26" VerticalAlignment="Bottom" Width="139" Click="UIelementShoot"/>       </Grid> </UserControl> 
by : ReLoadhttp://stackoverflow.com/users/445135

Answer: 4

For anyone else that stumbles upon this in the future, there is also the grand option of using phantomjs (http://phantomjs.org/)!

by : Bennyhttp://stackoverflow.com/users/194261




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog