How can I set the screenshot so that my screenshot is always in the center and the screenshot can be cut completely

This is my screeshot code

 private screenShot():void{
        var gui = AdvancedDynamicTexture.CreateFullscreenUI("UI");
        var btnScreenshot =  Button.CreateSimpleButton("but1", "截图");
        console.log(btnScreenshot)
        btnScreenshot.left = '300px'
        btnScreenshot.background ='red'
        btnScreenshot.width = "150px"
        btnScreenshot.height = "40px";
        btnScreenshot.color = "white";
        btnScreenshot.onPointerUpObservable.add(()=> {
            Tools.CreateScreenshotUsingRenderTarget(this.engine, this.camera, {
                width:240,
                height:400,
                precision: 5.5
            },
            function (data) {
              
                console.log(data)
            });
        });
        gui.addControl(btnScreenshot); 
        
    }

This is playground https://www.babylonjs-playground.com/#BGICGY#2 , When you zoom in and out, the screenshot will be incomplete

It is not incomplete for me. You get some transparent pixels either on the top/bottom or left/right image depending on the aspect ratio of the screen area with relation to the aspect ratio of the dimensions you set for the screenshot.

It can be easier to see it’s ok by removing the successCallback parameter of the CreateScreenshot call and letting the system creates a png for you.

Note that Chrome has some limitations regarding data url sizes (your 2nd post), it will truncate the display at some point. You should try in Firefox instead, which does not have this limitation (or at least it allows for bigger data urls).

2 Likes

OK , Thank you very much , I will try it again use your way.

1 Like