app.Screenshot() repeat same picture

145 views
Skip to first unread message

Chisan Gelu

unread,
Jul 23, 2022, 1:55:19 PM7/23/22
to DroidScript
Hi,In my html app , app.Screenshot() function generate the same image even it shoul generate diferrent images....
Is there an solution for this problem ?

Right2TheV0id

unread,
Jul 23, 2022, 3:25:37 PM7/23/22
to DroidScript
Hi,
You should elaborate and probably provide screenshots/code snippets to reproduce your issue if you want it to be investigated.

I made a simple code with two buttons, one to change the app background color and one to take and display the screenshot.
I noticed that using app.SetBackColor generate a correct screenshot each time the button is pressed.
But using document.body.style.background generate the correct screenshot only once, then regenerates the same screenshot again and again.
Not sure of what is going on here:

<html>
<head>
    <meta name="viewport" content="width=device-width">
    <script src='file:///android_asset/app.js'></script>
</head>
<body onload="app.Start()">
    <button type="button" onclick="ChangeColor()">ChangeColor()</button>
    <button type="button" onclick="ScreenShot()">ScreenShot()</button>
</body>
<script>
    var path = app.RealPath( "Misc" );
    var file = path + "/screenshot.jpg";
    var colors = [ "black", "white", "red", "green", "blue", "purple", "cyan" ];
    var index = -1;
    function OnStart() {
        if( !app.FolderExists( path ) )
            app.MakeFolder( path );
        ChangeColor();
    }
    function ChangeColor() {
        index = (++index)%colors.length;
        document.body.style.background = colors[index];
        //app.SetBackColor( colors[index] );
    }
    function ScreenShot() {
        app.ScreenShot( file );
        app.OpenFile( file, "image/jpeg", "Open with gallery" );
    }
</script>
</html>


Chisan Gelu

unread,
Jul 24, 2022, 1:26:53 AM7/24/22
to DroidScript

function doscreenshot(){
      var dt = new Date();
     
       var path = app.GetSpecialFolder( "Pictures" )+"/"+dt.toISOString()+".jpg";
     setTimeout(function(){app.ScreenShot(path);alert(language.efectuat + "\n" + path);app.OpenFile( path , "image/jpeg", "Choose Editor" );},500);
    }


This is my code.

Alan Hendry

unread,
Jul 24, 2022, 9:35:31 AM7/24/22
to DroidScript
HI,
The code below correctly takes a screen shot with a black background, then a green background.
I seem to recall previous posts that some controls don't appear on screenshots (webview, camera, dialog)
I believe it's built-in, and DS couldn't correct it.
Regards, ah

    doscreenshot()
    lay.SetBackColor("green")
    doscreenshot()

}
function doscreenshot(){
    var dt = new Date();
    var path = app.GetSpecialFolder( "Pictures" )+"/"+dt.toISOString()+".jpg";
    alert(path)
    app.ScreenShot(path)
}

Chisan Gelu

unread,
Jul 25, 2022, 8:49:40 AM7/25/22
to DroidScript
For html apps i found a good solution using a javascript library...



  function doscreenshot(){
   
  setTimeout(function(){      
const node = document.body;
const scale = 3000 / node.offsetWidth;
this.shot_loading = true;

domtoimage
.toJpeg(node, {
    height: node.offsetHeight * scale,
    width: node.offsetWidth * scale,
    style: {
    transform: "scale(" + scale + ")",
    transformOrigin: "top left",
    width: node.offsetWidth + "px",
    height: node.offsetHeight + "px"
    }
})
.then(dataUrl => {

    var dt = new Date();
        var path = app.GetSpecialFolder( "Pictures" )+"/Routes/"+dt.toISOString().replaceAll(":","")+".jpg";
        img = app.CreateImage( null,.3,.15);
        img.SetPixelData(dataUrl );
        img.Save(path);

        alert(language.efectuat + "\n" + path);
        app.OpenFile( path , "image/jpeg", "Choose Editor" );
})
.catch(error => {
    this.shot_loading = false;
    console.error("oops, something went wrong!", error);
});
 },500);
}

Alan Hendry

unread,
Jul 26, 2022, 7:23:28 AM7/26/22
to DroidScript
Reply all
Reply to author
Forward
0 new messages