private void setFillOverride(Paint fillOverride) {
   if (fillOverride instanceof Color) {
     Color c = (Color) fillOverride;
     progress.setStyle(
         "-fx-background-color: rgba("
             + ((int) (255 * c.getRed()))
             + ","
             + ""
             + ((int) (255 * c.getGreen()))
             + ","
             + ((int) (255 * c.getBlue()))
             + ","
             + ""
             + c.getOpacity()
             + ");");
   } else {
     progress.setStyle(null);
   }
 }
 private void rebuild() {
   // update indeterminate indicator
   final int segments = skin.indeterminateSegmentCount.get();
   opacities.clear();
   pathsG.getChildren().clear();
   final double step = 0.8 / (segments - 1);
   for (int i = 0; i < segments; i++) {
     Region region = new Region();
     region.setScaleShape(false);
     region.setCenterShape(false);
     region.getStyleClass().addAll("segment", "segment" + i);
     if (fillOverride instanceof Color) {
       Color c = (Color) fillOverride;
       region.setStyle(
           "-fx-background-color: rgba("
               + ((int) (255 * c.getRed()))
               + ","
               + ""
               + ((int) (255 * c.getGreen()))
               + ","
               + ((int) (255 * c.getBlue()))
               + ","
               + ""
               + c.getOpacity()
               + ");");
     } else {
       region.setStyle(null);
     }
     double opacity = Math.min(1, i * step);
     opacities.add(opacity);
     region.setOpacity(opacity);
     pathsG.getChildren().add(region);
   }
 }
Beispiel #3
0
 @Override
 public void encode(DataOutputStream os, Color c) throws IOException {
   os.writeDouble(c.getRed());
   os.writeDouble(c.getGreen());
   os.writeDouble(c.getBlue());
   os.writeDouble(c.getOpacity());
 }
 public static String encodeColorToRGBA(Color color) {
   final String result;
   if (color == null) {
     result = "null"; // NOI18N
   } else {
     final int red = (int) (color.getRed() * 255);
     final int green = (int) (color.getGreen() * 255);
     final int blue = (int) (color.getBlue() * 255);
     result = "rgba(" + red + "," + green + "," + blue + "," + color.getOpacity() + ")"; // NOI18N
   }
   return result;
 }
  /*
   * Private
   */
  private static String makeColorEncoding(Color c) {
    final int red, green, blue, alpha;
    final String result;

    red = (int) Math.round(c.getRed() * 255.0);
    green = (int) Math.round(c.getGreen() * 255.0);
    blue = (int) Math.round(c.getBlue() * 255.0);
    alpha = (int) Math.round(c.getOpacity() * 255.0);
    if (alpha == 255) {
      result = String.format((Locale) null, "#%02x%02x%02x", red, green, blue); // NOI18N
    } else {
      result = String.format((Locale) null, "#%02x%02x%02x%02x", red, green, blue, alpha); // NOI18N
    }

    return result;
  }
  public static int[][] convertImageTo2DIntArray(Image image, int width, int height) {

    int[][] returnArray = new int[height][width];

    // Obtain PixelReader
    PixelReader pixelReader = image.getPixelReader();

    int xSegmentLength = divideAByBThenRoundDown(image.getWidth(), width);
    int ySegmentLength = divideAByBThenRoundDown(image.getHeight(), height);

    BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);

    for (int row = 0; row < height; row++) {

      for (int column = 0; column < width; column++) {

        BufferedImage tempBufferedImage =
            bufferedImage.getSubimage(
                xSegmentLength * column, ySegmentLength * row, xSegmentLength, ySegmentLength);

        Color averageColor =
            AverageColorFinder.findAverageColorFromImage(
                SwingFXUtils.toFXImage(tempBufferedImage, null));

        int argb =
            ((int) (averageColor.getOpacity() * 255) << 24)
                | ((int) (averageColor.getRed() * 255) << 16)
                | ((int) (averageColor.getGreen() * 255) << 8)
                | ((int) (averageColor.getBlue() * 255));

        returnArray[row][column] = argb;
      }
    }

    return returnArray;
  }