List of usage examples for javafx.scene.image PixelReader getColor
public Color getColor(int x, int y);
From source file:net.rptools.tokentool.util.ImageUtil.java
private static Image processMagenta(Image inputImage, int colorThreshold, boolean overlayWanted) { int imageWidth = (int) inputImage.getWidth(); int imageHeight = (int) inputImage.getHeight(); WritableImage outputImage = new WritableImage(imageWidth, imageHeight); PixelReader pixelReader = inputImage.getPixelReader(); PixelWriter pixelWriter = outputImage.getPixelWriter(); for (int readY = 0; readY < imageHeight; readY++) { for (int readX = 0; readX < imageWidth; readX++) { Color pixelColor = pixelReader.getColor(readX, readY); if (isMagenta(pixelColor, COLOR_THRESHOLD) == overlayWanted) pixelWriter.setColor(readX, readY, Color.TRANSPARENT); else/*from w w w.j a va 2 s .c om*/ pixelWriter.setColor(readX, readY, pixelColor); } } return outputImage; }
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 . co 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 a v a 2s.co 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); }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param imgRect/*www . j a va2s .com*/ * @param iRapport * @return image transforme Mercator */ private static Image imgTransformationImage(Image imgRect, int iRapport) { int iLargeur = (int) imgRect.getWidth() / iRapport; int iHauteur = iLargeur / 2 / iRapport; WritableImage imgMercator = new WritableImage(iLargeur, iHauteur); PixelReader prRect = imgRect.getPixelReader(); PixelWriter pwMercator = imgMercator.getPixelWriter(); for (int i = 0; i < iLargeur; i++) { for (int j = 0; j < iHauteur; j++) { double phi = Math.asin(2.d * (iHauteur / 2.d - j) / iHauteur); int y2 = (int) (iHauteur * iRapport * (0.5d - phi / Math.PI)); if (y2 >= iHauteur * iRapport) { y2 = iHauteur * iRapport - 1; } Color clPixel = prRect.getColor(i * iRapport, y2 * iRapport); pwMercator.setColor(i, j, clPixel); } } return imgMercator; }