How can I get alpha of shading colors ?

Hi, I'm trying the parse Shading elements in java, but I don't know how to get the alpha of colors.

I'm doing it like this

{code}

for (Element element = reader.next(); element != null; element = reader.next()) {
    switch (element.getType()) {
        case Element.e_shading: {
            if (element.isOCVisible()) {
              Shading shading = element.getShading();
              if (shading.getType() == Shading.e_radial_shading) {

                //Is there another/easier way than this to access shading colors ?
                Obj funct_obj = shading.getSDFObj().findObj("Function");
              Function function = new Function(funct_obj);
              ArrayList<Color> gradientColors = new ArrayList<Color>();
              if (function.getType() == Function.e_stitching) {
            Obj bounds = function.getSDFObj().findObj("Bounds");

            //Get ratios of the shading
                  ArrayList<Float> ratios = new ArrayList<Float>();
                  ratios.add(0f);
                  for (int i = 0; i < bounds.size(); i++) {
                      ratios.add((float) bounds.getAt(i).getNumber());
                  }
                  ratios.add(1f);

                  //Get shading color per ratio
                  for (float ratio : ratios) {
                      ColorPt colPt = shading.getColor(ratio);

                      switch (shading.getBaseColorSpace().getType()) {
                        case (ColorSpace.e_device_rgb): {
                          int red = (int) Math.round(colPt.get(0) * 255);
                          int green = (int) Math.round(colPt.get(1) * 255);
                          int blue = (int) Math.round(colPt.get(2) * 255);
                          gradientColors.add(new Color(red, green, blue));

                          // How can I get alpha of my stop color ?

                      }
                      }
                  }
              }
            }
      }
    }
  }
}

{code}

Is it the proper way to parse gradients ? I didn't find anything on the web... What about other color spaces ?
How can I get the alpha of my colors ?
When I save my pdf into svg I can see that my colors have alphas

{code}
<stop offset="0.5744" style="stop-color:#130C0E;stop-opacity:0"/>
<stop offset="0.7977" style="stop-color:#130C0E;stop-opacity:0.6512"/>
<stop offset="1" style="stop-color:#130C0E;stop-opacity:0.95"/>
{code}

About ratios, I'm using "Bounds", but it only returns my 2 values "0.5744 and 0.7977" but in the svg I can see that there is also a third color with ratio "1". On another gradient I also saw "0" in the svg, that's why I manually add "0 and 1" but is it correct ... ?

Thanks for help :slight_smile:

Jean

Hi Jean,

It would be a lot better if you explained what your overall goal/objective is, before we go into these sorts of details. There is probably an easier way to go about what you are trying to do.