views:

508

answers:

4

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!

A: 

Did you find a solution for this? How much time do support staff waste trying to explain to users how to take a screen shot and email it? Sure would be nice to have a menu option or button right on the page... I'm hoping to find a Silverlight solution.

GeorgeBarker
Not yet, but I'm hoping there will be a way sometime soon.
Benny
A: 

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;
}
Peter Gfader
You could Render an image of the Silverlight UI and do anything with that, which really isn't a security risk at all (as Silverlight won't "see" outside of the silverlight sandbox).the line PageVisual = LayoutRoot isn't doing anything more than using the Visual's for the current Silverlight UI.
WPCoder
+1  A: 

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.

WPCoder
A: 

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>
ReLoad