Android-runtime: A float[] array?

Created on 29 May 2018  路  2Comments  路  Source: NativeScript/android-runtime

_From @xeroxstar on May 28, 2018 10:57_

Hello, it's not a bug rather a question that i am struggling to answer, i am trying to pass a float[] from native script to java but i find no way to do it:

Here is a code:

 float[] colorTransform = {
            0, 1f, 0, 0, 0, 
            0, 0, 0f, 0, 0,
            0, 0, 0, 0f, 0, 
            0, 0, 0, 1f, 0
};

    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0f); //Remove Colour 
    colorMatrix.set(colorTransform);

How can i create a float array for colorTransform in nativescript? Thanks!

_Copied from original issue: NativeScript/NativeScript#5874_

question

Most helpful comment

You could use the Array.create method to instantiate a primitive float[]:

const colorTransform = Array.create("float", 20);

colorTransform[0] = 0;
colorTransform[1] = 1;
colorTransform[2] = 0;
colorTransform[3] = 0;
colorTransform[4] = 0;
colorTransform[5] = 0;
colorTransform[6] = 0;
colorTransform[7] = 0;
colorTransform[8] = 0;
colorTransform[9] = 0;
colorTransform[10] = 0;
colorTransform[11] = 0;
colorTransform[12] = 0;
colorTransform[13] = 0;
colorTransform[14] = 0;
colorTransform[15] = 0;
colorTransform[16] = 0;
colorTransform[17] = 0;
colorTransform[18] = 1;
colorTransform[19] = 0;

const colorMatrix = new android.graphics.ColorMatrix();
colorMatrix.setSaturation(0);
colorMatrix.set(colorTransform);

All 2 comments

You could use the Array.create method to instantiate a primitive float[]:

const colorTransform = Array.create("float", 20);

colorTransform[0] = 0;
colorTransform[1] = 1;
colorTransform[2] = 0;
colorTransform[3] = 0;
colorTransform[4] = 0;
colorTransform[5] = 0;
colorTransform[6] = 0;
colorTransform[7] = 0;
colorTransform[8] = 0;
colorTransform[9] = 0;
colorTransform[10] = 0;
colorTransform[11] = 0;
colorTransform[12] = 0;
colorTransform[13] = 0;
colorTransform[14] = 0;
colorTransform[15] = 0;
colorTransform[16] = 0;
colorTransform[17] = 0;
colorTransform[18] = 1;
colorTransform[19] = 0;

const colorMatrix = new android.graphics.ColorMatrix();
colorMatrix.setSaturation(0);
colorMatrix.set(colorTransform);

Thx @darind , it worked :)

Was this page helpful?
0 / 5 - 0 ratings