Example usage for javafx.scene.paint Color equals

List of usage examples for javafx.scene.paint Color equals

Introduction

In this page you can find the example usage for javafx.scene.paint Color equals.

Prototype

@Override
public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:net.rptools.tokentool.util.ImageUtil.java

private static boolean isMagenta(Color color, int fudge) {
    if (color.equals(Color.MAGENTA))
        return true;

    double r = color.getRed();
    double g = color.getGreen();
    double b = color.getBlue();

    if (Math.abs(r - b) > fudge)
        return false;

    if (g > r - fudge || g > b - fudge)
        return false;

    return true;//  ww w  .  j  ava  2  s  .c  om
}

From source file:net.rptools.tokentool.util.ImageUtil.java

private static Image clipImageWithMask(Image imageSource, Image imageMask) {
    int imageWidth = (int) imageMask.getWidth();
    int imageHeight = (int) imageMask.getHeight();

    WritableImage outputImage = new WritableImage(imageWidth, imageHeight);
    PixelReader pixelReader_Mask = imageMask.getPixelReader();
    PixelReader pixelReader_Source = imageSource.getPixelReader();
    PixelWriter pixelWriter = outputImage.getPixelWriter();

    for (int readY = 0; readY < imageHeight; readY++) {
        for (int readX = 0; readX < imageWidth; readX++) {
            Color pixelColor = pixelReader_Mask.getColor(readX, readY);

            if (pixelColor.equals(Color.TRANSPARENT))
                pixelWriter.setColor(readX, readY, pixelReader_Source.getColor(readX, readY));
        }/*from   w  w  w .  j av a2  s . c  o m*/
    }

    return outputImage;
}

From source file:net.rptools.tokentool.util.ImageUtil.java

private static Image autoCropImage(Image imageSource) {
    ImageView croppedImageView = new ImageView(imageSource);
    PixelReader pixelReader = imageSource.getPixelReader();

    int imageWidth = (int) imageSource.getWidth();
    int imageHeight = (int) imageSource.getHeight();
    int minX = imageWidth, minY = imageHeight, maxX = 0, maxY = 0;

    // Find the first and last pixels that are not transparent to create a bounding viewport
    for (int readY = 0; readY < imageHeight; readY++) {
        for (int readX = 0; readX < imageWidth; readX++) {
            Color pixelColor = pixelReader.getColor(readX, readY);

            if (!pixelColor.equals(Color.TRANSPARENT)) {
                if (readX < minX)
                    minX = readX;/*w ww .j  av a2s. c  o  m*/
                if (readX > maxX)
                    maxX = readX;

                if (readY < minY)
                    minY = readY;
                if (readY > maxY)
                    maxY = readY;
            }
        }
    }

    if (maxX - minX <= 0 || maxY - minY <= 0)
        return new WritableImage(1, 1);

    // Create a viewport to clip the image using snapshot
    Rectangle2D viewPort = new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
    SnapshotParameters parameter = new SnapshotParameters();
    parameter.setViewport(viewPort);
    parameter.setFill(Color.TRANSPARENT);

    return croppedImageView.snapshot(parameter, null);
}