Gui.takeScreenshot: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Takes screenshot of game screen and puts at /screenshots/ip_port folder. Accessible in CEF via screnshoots:// scheme.
Takes screenshot of game screen and puts at /screenshots/ip_port folder. Accessible in CEF via screenshots:// scheme. (Will be available in 0.4)
 
Edit: You can also use '''http://screenshots/name.png''' as a fetcher for your screen shot in CEF
 
 
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">gui.takeScreenshot(name, type, quality, compQuality);</syntaxhighlight>
<syntaxhighlight lang="javascript">gui.takeScreenshot(name, type, quality, compQuality);</syntaxhighlight>
Line 6: Line 10:
*'''type:''' Type of screenshot (0 - JPG, 1 - PNG, 2 - BMP)
*'''type:''' Type of screenshot (0 - JPG, 1 - PNG, 2 - BMP)
*'''quality:''' Quality (0 - 100)
*'''quality:''' Quality (0 - 100)
*'''compressionQuality:''' Compression quality (0 - 1000)
*'''compressionQuality:''' Compression quality (0 - 100)
==Example==
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
mp.gui.takeScreenshot("random.png", 1, 100, 0);
mp.gui.takeScreenshot("random.png", 1, 100, 0);
</syntaxhighlight>
</syntaxhighlight>
==Screenshot to Base64==
Use this code in CEF to get your image as base64 code and transfer it to server-side to save for future usage
*'''URL must be http based format as i mentioned above'''
<syntaxhighlight lang="javascript">
function toDataUrl(url, callback) {
   
    var xhr = new XMLHttpRequest();
    xhr.onload = function() {
        var reader = new FileReader();
        reader.onloadend = function() {
            callback(reader.result);
        }
        reader.readAsDataURL(xhr.response);
    };
   
    xhr.open('GET', url);
    xhr.responseType = 'blob';
    xhr.send();
}
</syntaxhighlight>
*Usage:
<syntaxhighlight lang="javascript">
toDataUrl(url, (dataURL) => {
    alert(`DataURL IS: ${dataURL}`)
})
</syntaxhighlight>
==See also==
==See also==
{{WebBrowser_function_c}}
{{Gui_definition_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]

Latest revision as of 08:23, 9 October 2020

Takes screenshot of game screen and puts at /screenshots/ip_port folder. Accessible in CEF via screenshots:// scheme. (Will be available in 0.4)

Edit: You can also use http://screenshots/name.png as a fetcher for your screen shot in CEF


Syntax

gui.takeScreenshot(name, type, quality, compQuality);

Required Arguments

  • name: String
  • type: Type of screenshot (0 - JPG, 1 - PNG, 2 - BMP)
  • quality: Quality (0 - 100)
  • compressionQuality: Compression quality (0 - 100)

Example

mp.gui.takeScreenshot("random.png", 1, 100, 0);

Screenshot to Base64

Use this code in CEF to get your image as base64 code and transfer it to server-side to save for future usage

  • URL must be http based format as i mentioned above
function toDataUrl(url, callback) {
    
    var xhr = new XMLHttpRequest();
    xhr.onload = function() {
        var reader = new FileReader();
        reader.onloadend = function() {
            callback(reader.result);
        }
        reader.readAsDataURL(xhr.response);
    };

    
    xhr.open('GET', url);
    xhr.responseType = 'blob';
    xhr.send();
}
  • Usage:
toDataUrl(url, (dataURL) => {
    alert(`DataURL IS: ${dataURL}`)
})

See also