User Tools

Site Tools


Privacy Policy


Version 2.50 is out since Jan 1st 2022

Frequently Asked Questions


Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax


Image pixel colour

This sample shows the colour where you touch an image.

Sample Code

var txt,orig;
//Called when application is started.
function OnStart() 
    //Create a layout with objects vertically centered. 
    var lay = app.CreateLayout( "Linear", "FillXY" );     
    //Create an image. 
    orig =  app.CreateImage( "/Sys/Img/Xylophone.png" );
    var img = app.CreateImage( "/Sys/Img/Xylophone.png",0.5,-1 ); 
    lay.AddChild( img ); 
    txt=app.CreateText("Touch Xylophone");
    //Add layout to app.     
    app.AddLayout( lay ); 
function img_OnTouchDown(ev)
   var color = getPixelColor(this,ev.X,ev.Y);
function getPixelColor(img,x,y)
var raw = img.GetPixelData( "RawBase64",
//Decode the base64 encoded string
var byteArray = atob(raw);
if (byteArray.length < 4) return("?");
var r = byteArray.charCodeAt(0);
var g = byteArray.charCodeAt(1);
var b = byteArray.charCodeAt(2);
var a = byteArray.charCodeAt(3);
var col = "#" + toHex(a) + toHex(r) +toHex(g) + toHex(b);
return col;
//Return the 2 digit hex version of value, padded with
//leading zeros when required
function toHex(value)
    return ("00" + value.toString(16)).substr(-2);
sample_code/image_pixel_color.txt · Last modified: 2015/09/24 21:17 (external edit)