Click here to Skip to main content
15,886,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have created one Confirmation box using silverlight, it's having two buttons(OK, Cancel). I have written screen capture code for "OK" button click whenever i clicked.I got the dll file from that solution(Confirmation box) and paste into it(.dll) in different silverlight projects for screen capturing(like PrtScn). But my problem is, By using that .dll I can't capture my silverlight whole web page in full screen during Confirmation box appeared on the page.It Captures only My Confirmation box,i need to capture whole page by using that .dll file..

please suggest any idea
Thank You!
XML
<Button x:Name="PrtScn"
    Content="Capture"
    Click="Capture_Click"
    VerticalAlignment="Center"
    Height="25"
    Grid.Row="1"
    Grid.Column="1"
    HorizontalAlignment="Left"
    Width="50"
    Margin="7,5,0,9"
    BorderThickness="2" TabIndex="1" />		

C#
private void Capture_Click(object sender, RoutedEventArgs e)
{
    double i = Application.Current.Host.Content.ActualWidth;
    var image = PrintScreen(this);
}

public static System.Windows.Controls.Image PrintScreen(UIElement element)
{
    int Width = Convert.ToInt32(HtmlPage.Window.Eval("screen.width").ToString());
    int Height = Convert.ToInt32(HtmlPage.Window.Eval("screen.height").ToString());
    WriteableBitmap writeableBitmap = new WriteableBitmap((UIElement)element, null);
    //WriteableBitmap writeableBitmap = new WriteableBitmap(1024,768);
    writeableBitmap.Invalidate();
    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
    img.Source = writeableBitmap;
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.Filter = "JPEG Files (*.jpeg)|*.jpeg";
    dialog.DefaultExt = ".jpeg";
    //dialog.Multiselect = false;
    //dialog.Filter = "All Files | *.*";
    if ((bool)dialog.ShowDialog())
    {
        using (Stream fs = dialog.OpenFile())
        {
            SaveToFile(writeableBitmap, fs);
            // SaveToFile(bitmap);
            MessageBox.Show("Screenshot Saved");
        }
    }
    return img;
}

private static void SaveToFile(WriteableBitmap bitmap, Stream fs)
{
    // private static String SaveToFile(WriteableBitmap bitmap)
    {
        int width = bitmap.PixelWidth;
        int height = bitmap.PixelHeight;
        int bands = 3;
        byte[][,] raster = new byte[bands][,];

        //Convert the Image to pass into FJCore

        for (int i = 0; i < bands; i++)
        {
            raster[i] = new byte[width, height];
        }

        for (int row = 0; row < height; row++)
        {
            for (int column = 0; column < width; column++)
            {
                int pixel = bitmap.Pixels[width * row + column];
                raster[0][column, row] = (byte)(pixel >> 16);
                raster[1][column, row] = (byte)(pixel >> 8);
                raster[2][column, row] = (byte)pixel;
            }
        }

        ColorModel model = new ColorModel { colorspace = ColorSpace.RGB };
        FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);

        //Encode the Image as a JPEG
        MemoryStream stream = new MemoryStream();
        FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
        encoder.Encode();

        //Back to the start
        stream.Seek(0, SeekOrigin.Begin);

        //Get the Bytes and write them to the stream
        byte[] binaryData = new Byte[stream.Length];
        long bytesRead;
    	bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
        fs.Write(binaryData, 0, binaryData.Length);
        // string base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
        // return base64String;
    }
}
Posted
Updated 6-Aug-15 19:53pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900