Search code examples
androidskmaps

SKPolyline setColor not giving correct color


I am using a method to create a color array however the SKPolyline is white instead of the desired pinkish color. Here's the code:

    public static float[] getPinkColorArray() {
       float[] colorArray = new float[4];
       colorArray[0] = 249f;
       colorArray[1] = 1f;
       colorArray[2] = 148f;
       colorArray[3] = 255f;

       return colorArray;
   }

I then use polyline.setColor(floatArray); and it creates a white polyline. If I use values 255, 0, 0, 255 I get a red line (which is correct).

tl;dr: How do I make a pink float array for an SKPolyline with values red:249, green:1, blue:148, no alpha.


Solution

  •     SKPolyline polyline = new SKPolyline();
        // set the nodes on the polyline
        nodes = new ArrayList<SKCoordinate>();
        nodes.add(new SKCoordinate(-122.4342, 37.7898));
        nodes.add(new SKCoordinate(-122.4141, 37.7898));
        nodes.add(new SKCoordinate(-122.4342, 37.7753));
        polyline.setNodes(nodes);
        // set polyline color
        polyline.setColor(new float[]{0.976470588f, 0.003921569f, 0.580392157f, 1f});
    
        polyline.setLineSize(10);
        polyline.setIdentifier(12);
        mapView.addPolyline(polyline);
    

    I used the function 1f = 255 then 0.976470588f = 249 enter image description here