Capture Control Into Image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baburk
    New Member
    • Oct 2006
    • 111

    Capture Control Into Image

    I wants to capture Table contents(ie. entire table) into image file in aspx page.

    How to do?.

    There is a code for captuer a portion of he screen.

    Cature a rectangle of the screen and save to a png file

    [CODE=javascript]var as=new ActiveXObject(" ActiveScreen.Ca pturer");
    as.CaptureRect( 200, 200, 400, 300);
    var fs=as.SaveToFil e("test3.png" );
    WScript.Echo("I mage Size = " + fs.toString() + "\r\n");[/CODE]

    But I want to capture only a particular control (Table) contents as image.
    Last edited by gits; Jan 4 '08, 08:34 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    so you may use a function like in the following example:

    Code:
    <script type="text/javascript">
    function get_coords(elem_id) {
        var node = document.getElementById(elem_id);
        var dims = {
            x: node.offsetLeft,
            y: node.offsetTop,
            w: node.offsetWidth,
            h: node.offsetHeight
        };
        
        return dims;
    }
    </script>
    <body onload="get_coords('my_table');">
    <table id="my_table">
        <tr>
            <td>test</td>
        </tr>
    </table>
    </body>
    that returns you an object with the coords for your CaptureRect(); method ...

    kind regards
    Last edited by gits; Jan 2 '12, 01:04 PM.

    Comment

    • baburk
      New Member
      • Oct 2006
      • 111

      #3
      Microsoft JScript runtime error: Automation server can't create object

      I had used this script to capture control and its contents as image


      [CODE=javascript] <script type="text/javascript">
      function get_coords(elem _id) {
      var node = document.getEle mentById(elem_i d);


      var as = new ActiveXObject(" ActiveScreen.Ca pturer");//Here I got this error
      as.CaptureRect( node.offsetLeft , node.offsetTop, node.offsetWidt h, node.offsetHeig ht);
      var fs=as.SaveToFil e("C:\Documen ts and Settings\arun.v .DBA-CORP\Desktop\Ba bu\test3.png");
      WScript.Echo("I mage Size = " + fs.toString() + "\r\n");

      var dims = {
      x: node.offsetLeft ,
      y: node.offsetTop,
      w: node.offsetWidt h,
      h: node.offsetHeig ht
      };
      return dims;
      }
      </script>[/CODE]

      Any one help me how to rectify the error.

      Thanks in advance.
      Last edited by gits; Jan 3 '08, 08:42 AM. Reason: added code tags

      Comment

      • baburk
        New Member
        • Oct 2006
        • 111

        #4
        GridView As Image

        This script gets the height , width, left, top of the GridView.

        Now I want to capture this gridview as image through this position.

        How can I?.

        [CODE=javascript]<SCRIPT LANGUAGE="JAVAS CRIPT">
        function capture()
        {
        var node = document.getEle mentById("GridV iew1");

        var dims = {
        x: node.offsetLeft ,
        y: node.offsetTop,
        w: node.offsetWidt h,
        h: node.offsetHeig ht
        };
        </script>[/CODE]
        Last edited by gits; Jan 3 '08, 08:20 AM. Reason: added code tags

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          hi ...

          please keep one topic in one thread ... don't double post your question.

          compare the code i provided with that you posted at least ... it will not work since it misses a bracket and the returnvalue for the dims.

          as i said you simply should call the function and store the result in a variable:

          [CODE=javascript]var dims = function get_coords(elem _id);[/CODE]
          now you could refer to the members of our dims-object like:

          [CODE=javascript]alert(dims.x);[/CODE]
          which alerts the left top position. put it into your CaptureRect()-method and it should work.

          make an attempt and post back in case you have further problems.

          kind regards

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            Originally posted by baburk
            I had used this script to capture control and its contents as image


            [CODE=javascript] <script type="text/javascript">
            function get_coords(elem _id) {
            var node = document.getEle mentById(elem_i d);


            var as = new ActiveXObject(" ActiveScreen.Ca pturer");//Here I got this error
            as.CaptureRect( node.offsetLeft , node.offsetTop, node.offsetWidt h, node.offsetHeig ht);
            var fs=as.SaveToFil e("C:\Documen ts and Settings\arun.v .DBA-CORP\Desktop\Ba bu\test3.png");
            WScript.Echo("I mage Size = " + fs.toString() + "\r\n");

            var dims = {
            x: node.offsetLeft ,
            y: node.offsetTop,
            w: node.offsetWidt h,
            h: node.offsetHeig ht
            };
            return dims;
            }
            </script>[/CODE]

            Any one help me how to rectify the error.

            Thanks in advance.
            threads merged again ... please don't spread the topic ... keep it in one thread!

            first use the following simplyfied code:

            [CODE=javascript]function get_coords(elem _id) {
            var node = document.getEle mentById(elem_i d);

            var dims = {
            x: node.offsetLeft ,
            y: node.offsetTop,
            w: node.offsetWidt h,
            h: node.offsetHeig ht
            };

            var capt_obj = new ActiveXObject(" ActiveScreen.Ca pturer");
            capt_obj.Captur eRect(dims.x, dims.y, dims.w, dims.h);

            var path = "C:\\Docume nts and Settings\\arun. v.DBA-CORP\\Desktop\\ Babu\\";
            var fs = capt_obj.SaveTo File(path + 'test3.png');

            WScript.Echo("I mage Size = " + fs.toString() + "\r\n");
            }
            [/CODE]
            show the call! how do you call that code?

            kind regards

            Comment

            • baburk
              New Member
              • Oct 2006
              • 111

              #7
              Hi,
              Though that heigth, width, top, bottom I want to capture the GridView Into an image and store in one place.

              There is a code for captuer a portion of the screen, This throws an exception (Microsoft JScript runtime error: Automation server can't create object).

              Cature a rectangle of the screen and save to a png file
              [CODE=javascript]var as=new ActiveXObject(" ActiveScreen.Ca pturer");
              as.CaptureRect( 200, 200, 400, 300);
              var fs=as.SaveToFil e("test3.png" );
              WScript.Echo("I mage Size = " + fs.toString() + "\r\n");[/CODE]

              So I am expecting help. How to capture the gridview as image.
              Last edited by gits; Jan 3 '08, 04:23 PM. Reason: added code tags

              Comment

              • baburk
                New Member
                • Oct 2006
                • 111

                #8
                I called like this

                [code=asp]<SCRIPT LANGUAGE="JAVAS CRIPT">
                function get_coords(elem _id) {
                var node = document.getEle mentById(elem_i d);

                var dims = {
                x: node.offsetLeft ,
                y: node.offsetTop,
                w: node.offsetWidt h,
                h: node.offsetHeig ht
                };

                var capt_obj = new ActiveXObject(" ActiveScreen.Ca pturer");
                capt_obj.Captur eRect(dims.x, dims.y, dims.w, dims.h);

                var path = "C:\\Docume nts and Settings\\arun. v.DBA-CORP\\Desktop\\ Babu\\";
                var fs = capt_obj.SaveTo File(path + 'test3.png');

                WScript.Echo("I mage Size = " + fs.toString() + "\r\n");
                }

                </script>


                </head>
                <body>
                <form id="form1" runat="server">
                <div>
                <br />
                &nbsp;
                <asp:Button ID="Button1" runat="server" OnClick="Button 1_Click" Text="Button" OnClientClick = "get_coords(Gri dView1);" Height="25px" />
                <asp:GridView ID="GridView1" runat="server">
                </asp:GridView>
                </div>
                </form>
                </body>
                </html>[/code]
                Last edited by gits; Jan 3 '08, 04:25 PM. Reason: added code tags

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  i assume that ID="GridView1" is not the real id of the control ... could you have a look at the source-code when the page is loaded and search for the id there?

                  kind regards

                  btw: are you sure you have access to the control? i mean does it work with fixed values?

                  Comment

                  • baburk
                    New Member
                    • Oct 2006
                    • 111

                    #10
                    Are you sure you have access to the control? i mean does it work with fixed values?

                    Yes It worked with fixed values.

                    In source also its id is

                    Code:
                    <table cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
                    		<tr>
                    			<th scope="col">Name</th><th scope="col">Age</th>
                    		</tr><tr>
                    			<td>Babu</td><td>26</td>
                    		</tr>
                    	</table>
                    Thanks
                    Last edited by acoder; Jan 2 '12, 01:50 PM.

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5390

                      #11
                      hi ...

                      please use code tags when posting source-code ...

                      could you alert elem_id at start of the get_coords()-method? ... i think you should adapt:

                      [CODE=asp]OnClientClick=" get_coords('Gri dView1');"[/CODE]
                      since the id has to be passed as a string ...

                      kind regards

                      Comment

                      • ChiragShah
                        New Member
                        • Dec 2011
                        • 1

                        #12
                        Its really helpful, but this code is not working online. i have gone through the other post in which i refer that, for this screen capture user need to change their browser's security settings. From this code i am able to get all values on nodes, but image is not saving on my local machine. kindly help

                        Comment

                        Working...