Java 类javafx.scene.image.PixelWriter 实例源码

项目:marathonv5    文件:ImageOperatorSample.java   
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) {
    PixelWriter pw = img.getPixelWriter();
    double w = img.getWidth();
    double h = img.getHeight();
    double xRatio = 0.0;
    double yRatio = 0.0;
    double hue = 0.0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            xRatio = x/w;
            yRatio = y/h;
            hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset;
            Color c = Color.hsb(hue, 1.0, 1.0);
            pw.setColor(x, y, c);
        }
    }
}
项目:marathonv5    文件:ImageOperatorSample.java   
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) {
    PixelWriter pw = img.getPixelWriter();
    double w = img.getWidth();
    double h = img.getHeight();
    double xRatio = 0.0;
    double yRatio = 0.0;
    double hue = 0.0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            xRatio = x/w;
            yRatio = y/h;
            hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset;
            Color c = Color.hsb(hue, 1.0, 1.0);
            pw.setColor(x, y, c);
        }
    }
}
项目:worldheatmap    文件:SimpleHeatMap.java   
private void updateHeatMap() {
    monochromeCanvas.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
    heatMap = new WritableImage(monochromeImage.widthProperty().intValue(), monochromeImage.heightProperty().intValue());
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    Color colorFromMonoChromeImage;
    double brightness;
    Color mappedColor;
    for (int y = 0 ; y < monochromeImage.getHeight() ; y++) {
        for (int x = 0 ; x < monochromeImage.getWidth(); x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            //brightness = computeLuminance(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
            //brightness = computeBrightness(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
            brightness = computeBrightnessFast(colorFromMonoChromeImage.getRed(), colorFromMonoChromeImage.getGreen(), colorFromMonoChromeImage.getBlue());
            mappedColor = getColorAt(mappingGradient, brightness);
            if (fadeColors) {
                //pixelWriter.setColor(x, y, Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness));
                pixelWriter.setColor(x, y, Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), colorFromMonoChromeImage.getOpacity()));
            } else {
                pixelWriter.setColor(x, y, mappedColor);
            }
        }
    }
    heatMapView.setImage(heatMap);
}
项目:worldheatmap    文件:HeatMap.java   
/**
 * Recreates the heatmap based on the current monochrome map.
 * Using this approach makes it easy to change the used color
 * mapping.
 */
private void updateHeatMap() {
    monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);
    heatMap = new WritableImage(monochromeImage.widthProperty().intValue(), monochromeImage.heightProperty().intValue());
    Color       colorFromMonoChromeImage;
    double      brightness;
    Color       mappedColor;
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    int width  = (int) monochromeImage.getWidth();
    int height = (int) monochromeImage.getHeight();
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            brightness               = colorFromMonoChromeImage.getOpacity();
            mappedColor              = getColorAt(mappingGradient, brightness);
            pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
        }
    }
    setImage(heatMap);
}
项目:charts    文件:HeatMap.java   
/**
 * Recreates the heatmap based on the current monochrome map.
 * Using this approach makes it easy to change the used color
 * mapping.
 */
private void updateHeatMap() {
    monochrome.snapshot(SNAPSHOT_PARAMETERS, monochromeImage);

    int width  = monochromeImage.widthProperty().intValue();
    int height = monochromeImage.heightProperty().intValue();
    heatMap    = new WritableImage(width, height);

    Color       colorFromMonoChromeImage;
    double      brightness;
    Color       mappedColor;
    PixelWriter pixelWriter = heatMap.getPixelWriter();
    PixelReader pixelReader = monochromeImage.getPixelReader();
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            colorFromMonoChromeImage = pixelReader.getColor(x, y);
            brightness               = colorFromMonoChromeImage.getOpacity();
            mappedColor              = Helper.getColorAt(mappingGradient, brightness);
            pixelWriter.setColor(x, y, fadeColors ? Color.color(mappedColor.getRed(), mappedColor.getGreen(), mappedColor.getBlue(), brightness) : mappedColor);
        }
    }
    setImage(heatMap);
}
项目:jmonkeybuilder    文件:SingleColorTextureFileCreator.java   
@Override
@FXThread
protected boolean validate(@NotNull final VarTable vars) {

    final Color color = UIUtils.from(vars.get(PROP_COLOR, ColorRGBA.class));

    final int width = vars.getInteger(PROP_WIDTH);
    final int height = vars.getInteger(PROP_HEIGHT);

    final WritableImage writableImage = new WritableImage(width, height);
    final PixelWriter pixelWriter = writableImage.getPixelWriter();

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            pixelWriter.setColor(i, j, color);
        }
    }

    getImageView().setImage(writableImage);
    return true;
}
项目:jmonkeybuilder    文件:SingleColorTextureFileCreator.java   
@Override
@BackgroundThread
protected void writeData(@NotNull final VarTable vars, final @NotNull Path resultFile) throws IOException {
    super.writeData(vars, resultFile);

    final Color color = UIUtils.from(vars.get(PROP_COLOR, ColorRGBA.class));

    final int width = vars.getInteger(PROP_WIDTH);
    final int height = vars.getInteger(PROP_HEIGHT);

    final WritableImage writableImage = new WritableImage(width, height);
    final PixelWriter pixelWriter = writableImage.getPixelWriter();

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            pixelWriter.setColor(i, j, color);
        }
    }

    final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(writableImage, null);

    try (final OutputStream out = Files.newOutputStream(resultFile)) {
        ImageIO.write(bufferedImage, "png", out);
    }
}
项目:minecraft-jfx-skin    文件:SkinHelper.java   
public void copy(float srcX, float srcY, float toX, float toY, float width, float height, boolean reversalX, boolean reversalY) {
    PixelReader reader = srcImage.getPixelReader();
    PixelWriter writer = newImage.getPixelWriter();
    int srcScaleX = (int) srcImage.getWidth();
    int srcScaleY = (int) srcImage.getHeight();
    int newScaleX = (int) newImage.getWidth();
    int newScaleY = (int) newImage.getHeight();
    int srcWidth  = (int) (width * srcScaleX);
    int srcHeight = (int) (height * srcScaleY);

    for (int x = 0; x < srcWidth; x++)
        for (int y = 0; y < srcHeight; y++)
            writer.setArgb((int) (toX * newScaleX + x), (int) (toY * newScaleY + y),
                    reader.getArgb((int) (srcX * srcScaleX + (reversalX ? srcWidth - x - 1 : x)),
                            (int) (srcY * srcScaleY + (reversalY ? srcHeight - y - 1 : y))));
}
项目:openjfx-8u-dev-tests    文件:WriteSingleColorImageTestBase.java   
@Override
protected Image getImage() {
    WritableImage image = new WritableImage(256, 256);

    PixelWriter pixelWriter = image.getPixelWriter();


    for (int i = 0; i < 256; i++) {
        for (int j = 0; j < 256; j++) {
            double color = i + j;
            pixelWriter.setColor(i, j,
                    getColorComponentProvider().getColor(
                    ((color > 255) ? 255.0 : color) / 255));

        }
    }

    return image;
}
项目:openjfx-8u-dev-tests    文件:WriteSingleARGBImageTestBase.java   
@Override
protected Image getImage() {
    WritableImage image = new WritableImage(256, 256);
    PixelWriter pixelWriter = image.getPixelWriter();

    for (int i = 0; i < 256; i++) {
        for (int j = 0; j < 256; j++) {
            int color = i + j;

            pixelWriter.setArgb(i, j,
                    getColorComponentProvider().getARGBColor(
                    ((color > 255) ? 255 : color)));
        }
    }

    return image;
}
项目:Medusa    文件:Helper.java   
public static Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    if (Double.compare(WIDTH, 0) <= 0 || Double.compare(HEIGHT, 0) <= 0) return null;
    int                 width                   = (int) WIDTH;
    int                 height                  = (int) HEIGHT;
    double              alphaVariationInPercent = Helper.clamp(0.0, 100.0, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE                   = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER            = IMAGE.getPixelWriter();
    final Random        BW_RND                  = new Random();
    final Random        ALPHA_RND               = new Random();
    final double        ALPHA_START             = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION         = alphaVariationInPercent / 100;
    for (int y = 0 ; y < height ; y++) {
        for (int x = 0 ; x < width ; x++) {
            final Color  NOISE_COLOR = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            final double NOISE_ALPHA = Helper.clamp(0.0, 1.0, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(NOISE_COLOR.getRed(), NOISE_COLOR.getGreen(), NOISE_COLOR.getBlue(), NOISE_ALPHA));
        }
    }
    return IMAGE;
}
项目:Alchemy    文件:SkinHelper.java   
public void copy(float srcX, float srcY, float toX, float toY, float width, float height, boolean reversalX, boolean reversalY) {
    PixelReader reader = srcImage.getPixelReader();
    PixelWriter writer = newImage.getPixelWriter();
    int srcScaleX = (int) srcImage.getWidth();
    int srcScaleY = (int) srcImage.getHeight();
    int newScaleX = (int) newImage.getWidth();
    int newScaleY = (int) newImage.getHeight();
    int srcWidth  = (int) (width * srcScaleX);
    int srcHeight = (int) (height * srcScaleY);

    for (int x = 0; x < srcWidth; x++)
        for (int y = 0; y < srcHeight; y++)
            writer.setArgb((int) (toX * newScaleX + x), (int) (toY * newScaleY + y),
                    reader.getArgb((int) (srcX * srcScaleX + (reversalX ? srcWidth - x - 1 : x)),
                            (int) (srcY * srcScaleY + (reversalY ? srcHeight - y - 1 : y))));
}
项目:Krothium-Launcher    文件:TexturePreview.java   
/**
 * Renders a layer. Transparent colors and background color is ignored.
 * @param dstx Destination X
 * @param dsty Destination Y
 * @param w Width of the chunk
 * @param h Height of the chunk
 * @param pr The image pixel reader
 * @param pw The output pixel writer
 * @param srcx The X coordinate from the source skin
 * @param srcy The Y coordinate from the source skin
 */
private static void renderLayer(int dstx, int dsty, int w, int h, PixelReader pr, PixelWriter pw, int srcx, int srcy) {
    Color background = pr.getColor(0, 0);
    int x_origin = dstx;
    for (int y = srcy; y < srcy + h; y++){
        for (int x = srcx; x < srcx + w; x++) {
            Color c = pr.getColor(x, y);
            if (c.getOpacity() == 1 && !c.equals(background)) {
                pw.setColor(dstx, dsty, c);
            }
            dstx++;
        }
        dsty++;
        dstx = x_origin;
    }
}
项目:Krothium-Launcher    文件:Kernel.java   
/**
 * This method receives an image scales it
 * @param input Input image
 * @param scaleFactor Output scale factor
 * @return The resampled image
 */
public Image resampleImage(Image input, int scaleFactor) {
    int W = (int) input.getWidth();
    int H = (int) input.getHeight();
    WritableImage output = new WritableImage(
            W * scaleFactor,
            H * scaleFactor
    );
    PixelReader reader = input.getPixelReader();
    PixelWriter writer = output.getPixelWriter();
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            int argb = reader.getArgb(x, y);
            for (int dy = 0; dy < scaleFactor; dy++) {
                for (int dx = 0; dx < scaleFactor; dx++) {
                    writer.setArgb(x * scaleFactor + dx, y * scaleFactor + dy, argb);
                }
            }
        }
    }
    return output;
}
项目:blasteroids    文件:RenderUtils.java   
/**
   * Colorizes an image by the given amount
   * 
   * @param img Image
   * @param c Color
   * @param a Double amount
   * @return Image
   */
  public static Image colorizeImage(Image img, Color c, double a) {
    PixelReader reader = img.getPixelReader();
WritableImage write = new WritableImage((int) img.getWidth(), (int) img.getHeight());
PixelWriter writer = write.getPixelWriter();

for(int readY = 0; readY < img.getHeight(); readY++){
    for(int readX = 0; readX < img.getWidth(); readX++) {
        Color color = reader.getColor(readX, readY);
        if(color.getOpacity() == 0) continue;
        color = color.interpolate(c, a);
        writer.setColor(readX, readY, color);
    }
}

return (Image) write;
  }
项目:streamplify    文件:ShufflerView.java   
Image createImage(BigInteger startIndex, int count, long step) {
    int width = idxCount.subtract(BigInteger.ONE).bitLength();
    WritableImage img = new WritableImage(2 * width, 2 * count);
    PixelWriter pw  = img.getPixelWriter();
    for (int y = 0 ; y < count ; y++) {
        BigInteger idx = startIndex.add(BigInteger.valueOf(y * step));
        BigInteger shuffIdx = shuffler.getShuffledIndex(idx, idxCount);
        boolean[] shuffledBits = toBoolBits(shuffIdx, idxCount);
        for (int x = 0 ; x < width ; x++) {
            Color color = shuffledBits[x] ? Color.BLACK : Color.WHITE;
            pw.setColor(2 * x, 2 * y, color);
            pw.setColor(2 * x + 1, 2 * y, color);
            pw.setColor(2 * x, 2 * y + 1, color);
            pw.setColor(2 * x + 1, 2 * y + 1, color);
        }
    }
    return img;
}
项目:FXImgurUploader    文件:LcdSkin.java   
private Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    int width  = WIDTH <= 0 ? (int) PREFERRED_WIDTH : (int) WIDTH;
    int height = HEIGHT <= 0 ? (int) PREFERRED_HEIGHT : (int) HEIGHT;
    double alphaVariationInPercent      = getSkinnable().clamp(0, 100, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE           = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER    = IMAGE.getPixelWriter();
    final Random        BW_RND          = new Random();
    final Random        ALPHA_RND       = new Random();
    final double        ALPHA_START     = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION = alphaVariationInPercent / 100;
    Color noiseColor;
    double noiseAlpha;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
        }
    }
    return IMAGE;
}
项目:FXImgurUploader    文件:LcdClockSkin.java   
private Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    int width  = WIDTH <= 0 ? (int) PREFERRED_WIDTH : (int) WIDTH;
    int height = HEIGHT <= 0 ? (int) PREFERRED_HEIGHT : (int) HEIGHT;
    double alphaVariationInPercent      = getSkinnable().clamp(0, 100, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE           = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER    = IMAGE.getPixelWriter();
    final Random        BW_RND          = new Random();
    final Random        ALPHA_RND       = new Random();
    final double        ALPHA_START     = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION = alphaVariationInPercent / 100;
    Color  noiseColor;
    double noiseAlpha;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
        }
    }
    return IMAGE;
}
项目:JFoenix    文件:JFXColorPickerUI.java   
private Image getHuesCircle(int width, int height) {
    WritableImage raster = new WritableImage(width, height);
    PixelWriter pixelWriter = raster.getPixelWriter();
    Point2D center = new Point2D((double) width / 2, (double) height / 2);
    double rsmall = 0.8 * width / 2;
    double rbig = (double) width / 2;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double dx = x - center.getX();
            double dy = y - center.getY();
            double distance = Math.sqrt((dx * dx) + (dy * dy));
            double o = Math.atan2(dy, dx);
            if (distance > rsmall && distance < rbig) {
                double H = map(o, -Math.PI, Math.PI, 0, 255);
                double S = 255;
                double L = 152;
                pixelWriter.setColor(x, y, HSL2RGB(H, S, L));
            }
        }
    }
    return raster;
}
项目:fr.xs.jtk    文件:Palette.java   
public Image createPalette(boolean save){
    if(numColors<1){
        return null;
    }
    // try to create a square image
    width=(int)Math.sqrt(numColors);
    height=numColors/width;

    imgPalette = new WritableImage(width, height);
    PixelWriter   pw  = ((WritableImage)imgPalette).getPixelWriter();
    AtomicInteger count = new AtomicInteger();
    IntStream.range(0, height).boxed()
            .forEach(y->IntStream.range(0, width).boxed()
                    .forEach(x->pw.setColor(x, y, getColor(count.getAndIncrement()))));
    if(save){
        saveImage();
    }
    return imgPalette;
}
项目:reversegeocode    文件:BuildLayeredIndex.java   
/**
 * Visualize the map.
 *
 * @param Maximum
 *            color
 * @param winner
 *            Winners array
 */
public void visualize(int max, int[][] winner) {
   LOG.warn("Producing visualization.");
    // Randomly assign colors for visualization:
    Random r = new Random();
    int[] cols = new int[max + 1];
    for (int i = 1; i < cols.length; i++) {
        cols[i] = r.nextInt(0x1000000) | 0xFF000000;
    }
    try {
        WritableImage writableImage = new WritableImage(viewport.width,
                viewport.height);
        PixelWriter writer = writableImage.getPixelWriter();
        for (int y = 0; y < viewport.height; y++) {
            // Note: visualization is drawn upside down.
            int[] row = winner[viewport.height - 1 - y];
            for (int x = 0; x < viewport.width; x++) {
                writer.setArgb(x, y, cols[row[x]]);
            }
        }
        ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png",
                imfile);
    } catch (IOException e) {
        LOG.error("IO error writing visualization.", e);
    }
}
项目:FlagMaker-2    文件:ColorSelector.java   
private void FillHueCanvas()
{
    int width = (int)cnvHue.getWidth();
    int height = (int)cnvHue.getHeight();
    WritableImage img = new WritableImage(width, height);
    PixelWriter pw = img.getPixelWriter();

    for (int y = 0; y < height; y++)
    {
        Color color = Color.hsb(360.0 * y / height, 1, 1);
        for (int x = 0; x < width; x++)
        {
            pw.setColor(x, y, color);
        }
    }

    GraphicsContext gc = cnvHue.getGraphicsContext2D();
    gc.drawImage(img, 0, 0);
}
项目:FlagMaker-2    文件:ColorSelector.java   
private void FillSatLightCanvas(Color input)
{
    int width = (int)cnvSatLight.getWidth();
    int height = (int)cnvSatLight.getHeight();
    WritableImage img = new WritableImage(width, height);
    PixelWriter pw = img.getPixelWriter();

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            Color color = Color.hsb(input.getHue(), x / (double)width, 1 - y / (double)height);
            pw.setColor(x, y, color);
        }
    }

    GraphicsContext gc = cnvSatLight.getGraphicsContext2D();
    gc.drawImage(img, 0, 0);
}
项目:FXyzLib    文件:Palette.java   
public Image createPalette(boolean save){
    if(numColors<1){
        return null;
    }
    // try to create a square image
    width=(int)Math.sqrt(numColors);
    height=numColors/width;

    imgPalette = new WritableImage(width, height);
    PixelWriter   pw  = ((WritableImage)imgPalette).getPixelWriter();
    AtomicInteger count = new AtomicInteger();
    IntStream.range(0, height).boxed()
            .forEach(y->IntStream.range(0, width).boxed()
                    .forEach(x->pw.setColor(x, y, getColor(count.getAndIncrement()))));
    if(save){
        saveImage();
    }
    return imgPalette;
}
项目:org.csstudio.display.builder    文件:ColorMapDialog.java   
/** Update color bar in UI from current 'map' */
private void updateColorBar()
{
    // On Mac OS X it was OK to create an image sized 256 x 1:
    // 256 wide to easily set the 256 colors,
    // 1 pixel height which is then stretched via the BackgroundSize().
    // On Linux, the result was garbled unless the image height matched the
    // actual height, so it's now fixed to COLOR_BAR_HEIGHT
    final WritableImage colors = new WritableImage(256, COLOR_BAR_HEIGHT);
    final PixelWriter writer = colors.getPixelWriter();
    for (int x=0; x<256; ++x)
    {
        final int arfb = ColorMappingFunction.getRGB(map.getColor(x));
        for (int y=0; y<COLOR_BAR_HEIGHT; ++y)
            writer.setArgb(x, y, arfb);
    }
    // Stretch image to fill color_bar
    color_bar.setBackground(new Background(
            new BackgroundImage(colors, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
                                BackgroundPosition.DEFAULT,
                                new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true))));
}
项目:org.csstudio.display.builder    文件:ImageScaling.java   
@Override
public void start(final Stage stage)
{
    // Image with red border
    final WritableImage image = new WritableImage(WIDTH, HEIGHT);
    final PixelWriter writer = image.getPixelWriter();
    for (int x=0; x<WIDTH; ++x)
    {
        writer.setColor(x, 0, Color.RED);
        writer.setColor(x, HEIGHT-1, Color.RED);
    }
    for (int y=0; y<HEIGHT; ++y)
    {
        writer.setColor(0, y, Color.RED);
        writer.setColor(WIDTH-1, y, Color.RED);
    }

    // Draw into canvas, scaling 'up'
    final Canvas canvas = new Canvas(800, 600);
    canvas.getGraphicsContext2D().drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight());

    final Scene scene = new Scene(new Group(canvas), canvas.getWidth(), canvas.getHeight());
    stage.setScene(scene);
    stage.show();
}
项目:FXTutorials    文件:BasicEncoder.java   
@Override
public Image encode(Image image, String message) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();

    WritableImage copy = new WritableImage(image.getPixelReader(), width, height);
    PixelWriter writer = copy.getPixelWriter();
    PixelReader reader = image.getPixelReader();

    boolean[] bits = encode(message);

    IntStream.range(0, bits.length)
            .mapToObj(i -> new Pair<>(i, reader.getArgb(i % width, i / width)))
            .map(pair -> new Pair<>(pair.getKey(), bits[pair.getKey()] ? pair.getValue() | 1 : pair.getValue() &~ 1))
            .forEach(pair -> {
                int x = pair.getKey() % width;
                int y = pair.getKey() / width;

                writer.setArgb(x, y, pair.getValue());
            });

    return copy;
}
项目:JavaOne2015JavaFXPitfalls    文件:PixelWriterTest.java   
private void testARGB(PixelReader reader, int width, int height) {
    for (int i = 0; i < 10; i++) {
        WritableImage dest = new WritableImage(width, height);
        PixelWriter writer = dest.getPixelWriter();

        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                // reading a pixel from src image,
                // then writing a pixel to dest image
                //Color color = reader.getColor(x, y);
                //writer.setColor(x, y, color);

                // this way is also OK
                int argb = reader.getArgb(x, y);
                writer.setArgb(x, y, argb);


            }
        }

    }
}
项目:Connected-Mind-Neural-Network    文件:Maze.java   
public Image getSquare(int xOrigin, int yOrigin, int width, int height)
{
    xOrigin = xOrigin > 0 ? xOrigin : 0;
    yOrigin = yOrigin > 0 ? yOrigin : 0;
    width = xOrigin + width <= _width ? width : _width - xOrigin;
    height = yOrigin + height <= _height ? height : _height - yOrigin;

    WritableImage image = new WritableImage(width, height);
    PixelWriter writer = image.getPixelWriter();

    for(int x = xOrigin; x < xOrigin + width; x++)
    {
        for(int y = yOrigin; y < yOrigin + height; y++)
        {
            Color color = _pixels.getColor(x, y);
            writer.setColor(x - xOrigin, y - yOrigin, color);
        }
    }

    return image;
}
项目:jace    文件:VideoDHGR.java   
protected void displayLores(WritableImage screen, int xOffset, int y, int rowAddress) {
    int c1 = ((RAM128k) computer.getMemory()).getMainMemory().readByte(rowAddress + xOffset) & 0x0FF;
    if ((y & 7) < 4) {
        c1 &= 15;
    } else {
        c1 >>= 4;
    }
    Color color = Palette.color[c1];
    // Unrolled loop, faster
    PixelWriter writer = screen.getPixelWriter();
    int xx = xOffset * 14;
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
}
项目:jace    文件:VideoDHGR.java   
protected void showDhgr(WritableImage screen, int xOffset, int y, int dhgrWord) {
    PixelWriter writer = screen.getPixelWriter();
    try {
        for (int i = 0; i < 7; i++) {
            Color color;
            if (!dhgrMode && hiresMode) {
                color = Palette.color[dhgrWord & 15];
            } else {
                color = Palette.color[FLIP_NYBBLE[dhgrWord & 15]];
            }
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            dhgrWord >>= 4;
        }
    } catch (ArrayIndexOutOfBoundsException ex) {
        Logger.getLogger(getClass().getName()).warning("Went out of bounds in video display");
    }
}
项目:jace    文件:VideoDHGR.java   
protected void showBW(WritableImage screen, int xOffset, int y, int dhgrWord) {
    // Using the data buffer directly is about 15 times faster than setRGB
    // This is because setRGB does extra (useless) color model logic
    // For that matter even Graphics.drawLine is faster than setRGB!
    // This is equivilant to y*560 but is 5% faster
    // Also, adding xOffset now makes it additionally 5% faster
    //int yOffset = ((y << 4) + (y << 5) + (y << 9))+xOffset;

    int xx = xOffset;
    PixelWriter writer = screen.getPixelWriter();
    for (int i = 0; i < 28; i++) {
        if (xx < 560) {
        // yOffset++ is used instead of yOffset+i, because it is faster
        writer.setColor(xx++, y, (dhgrWord & 1) == 1 ? WHITE : BLACK);
        }
        dhgrWord >>= 1;
    }
}
项目:tokentool    文件:ImageUtil.java   
public static Image resizeCanvas(Image imageSource, int newWidth, int newHeight, int offsetX, int offsetY) {
    int sourceWidth = (int) imageSource.getWidth();
    int sourceHeight = (int) imageSource.getHeight();

    // No work needed here...
    if (sourceWidth == newWidth && sourceHeight == newHeight)
        return imageSource;

    WritableImage outputImage = new WritableImage(newWidth, newHeight);
    PixelReader pixelReader = imageSource.getPixelReader();
    PixelWriter pixelWriter = outputImage.getPixelWriter();
    WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();

    int[] buffer = new int[sourceWidth * sourceHeight];
    pixelReader.getPixels(0, 0, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);
    pixelWriter.setPixels(offsetX, offsetY, sourceWidth, sourceHeight, format, buffer, 0, sourceWidth);

    return outputImage;
}
项目:tokentool    文件: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));
        }
    }

    return outputImage;
}
项目:tokentool    文件: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
                pixelWriter.setColor(readX, readY, pixelColor);

        }
    }

    return outputImage;
}
项目:kotlinfx-ensemble    文件:ImageOperatorSample.java   
private static void renderImage(WritableImage img, double gridSize, double hueFactor, double hueOffset) {
    PixelWriter pw = img.getPixelWriter();
    double w = img.getWidth();
    double h = img.getHeight();
    double xRatio = 0.0;
    double yRatio = 0.0;
    double hue = 0.0;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            xRatio = x/w;
            yRatio = y/h;
            hue = Math.sin(yRatio*(gridSize*Math.PI))*Math.sin(xRatio*(gridSize*Math.PI))*Math.tan(hueFactor/20.0)*360.0 + hueOffset;
            Color c = Color.hsb(hue, 1.0, 1.0);
            pw.setColor(x, y, c);
        }
    }
}
项目:Enzo    文件:LcdSkin.java   
private Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    int width  = WIDTH <= 0 ? (int) PREFERRED_WIDTH : (int) WIDTH;
    int height = HEIGHT <= 0 ? (int) PREFERRED_HEIGHT : (int) HEIGHT;
    double alphaVariationInPercent      = getSkinnable().clamp(0, 100, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE           = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER    = IMAGE.getPixelWriter();
    final Random        BW_RND          = new Random();
    final Random        ALPHA_RND       = new Random();
    final double        ALPHA_START     = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION = alphaVariationInPercent / 100;
    Color noiseColor;
    double noiseAlpha;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
        }
    }
    return IMAGE;
}
项目:Enzo    文件:LcdClockSkin.java   
private Image createNoiseImage(final double WIDTH, final double HEIGHT, final Color DARK_COLOR, final Color BRIGHT_COLOR, final double ALPHA_VARIATION_IN_PERCENT) {
    int width  = WIDTH <= 0 ? (int) PREFERRED_WIDTH : (int) WIDTH;
    int height = HEIGHT <= 0 ? (int) PREFERRED_HEIGHT : (int) HEIGHT;
    double alphaVariationInPercent      = getSkinnable().clamp(0, 100, ALPHA_VARIATION_IN_PERCENT);
    final WritableImage IMAGE           = new WritableImage(width, height);
    final PixelWriter   PIXEL_WRITER    = IMAGE.getPixelWriter();
    final Random        BW_RND          = new Random();
    final Random        ALPHA_RND       = new Random();
    final double        ALPHA_START     = alphaVariationInPercent / 100 / 2;
    final double        ALPHA_VARIATION = alphaVariationInPercent / 100;
    Color  noiseColor;
    double noiseAlpha;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            noiseColor = BW_RND.nextBoolean() == true ? BRIGHT_COLOR : DARK_COLOR;
            noiseAlpha = getSkinnable().clamp(0, 1, ALPHA_START + ALPHA_RND.nextDouble() * ALPHA_VARIATION);
            PIXEL_WRITER.setColor(x, y, Color.color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
        }
    }
    return IMAGE;
}
项目:lawless-legends    文件:VideoDHGR.java   
protected void displayLores(WritableImage screen, int xOffset, int y, int rowAddress) {
    int c1 = ((RAM128k) computer.getMemory()).getMainMemory().readByte(rowAddress + xOffset) & 0x0FF;
    if ((y & 7) < 4) {
        c1 &= 15;
    } else {
        c1 >>= 4;
    }
    Color color = Palette.color[c1];
    // Unrolled loop, faster
    PixelWriter writer = screen.getPixelWriter();
    int xx = xOffset * 14;
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
    writer.setColor(xx++, y, color);
}
项目:lawless-legends    文件:VideoDHGR.java   
protected void showDhgr(WritableImage screen, int xOffset, int y, int dhgrWord) {
    PixelWriter writer = screen.getPixelWriter();
    try {
        for (int i = 0; i < 7; i++) {
            Color color;
            if (!dhgrMode && hiresMode) {
                color = Palette.color[dhgrWord & 15];
            } else {
                color = Palette.color[FLIP_NYBBLE[dhgrWord & 15]];
            }
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            writer.setColor(xOffset++, y, color);
            dhgrWord >>= 4;
        }
    } catch (ArrayIndexOutOfBoundsException ex) {
        Logger.getLogger(getClass().getName()).warning("Went out of bounds in video display");
    }
}