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

下面列出了怎么用javafx.scene.image.PixelWriter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: chart-fx   文件: WriteFxImage.java
/**
 * copy the given Image to a WritableImage
 * 
 * @param image the input image
 * @return clone of image
 */
public static WritableImage clone(Image image) {
    int height = (int) image.getHeight();
    int width = (int) image.getWidth();
    WritableImage writableImage = WritableImageCache.getInstance().getImage(width, height);
    PixelWriter pixelWriter = writableImage.getPixelWriter();
    if (pixelWriter == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }

    final PixelReader pixelReader = image.getPixelReader();
    if (pixelReader == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            Color color = pixelReader.getColor(x, y);
            pixelWriter.setColor(x, y, color);
        }
    }
    return writableImage;
}
 
源代码2 项目: oim-fx   文件: HeadImagePanel.java
private void setGrayImage(Image image) {
	if (null != image && !image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			if (null != pixelWriter && null != pixelReader) {
				for (int y = 0; y < imageHeight; y++) {
					for (int x = 0; x < imageWidth; x++) {
						Color color = pixelReader.getColor(x, y);
						color = color.grayscale();
						pixelWriter.setColor(x, y, color);
					}
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
源代码3 项目: oim-fx   文件: HeadImageItemPane.java
private void setGrayImage(Image image) {
	if (null != image&&!image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
源代码4 项目: oim-fx   文件: ImagePane.java
private void setGrayImage(Image image) {
	if (null != image && !image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
源代码5 项目: MyBox   文件: FxmlImageManufacture.java
public static Image cropInsideFx(Image image, DoubleShape shape, Color bgColor) {
    if (image == null || shape == null || !shape.isValid()
            || bgColor == null) {
        return image;
    }
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (shape.include(x, y)) {
                pixelWriter.setColor(x, y, bgColor);
            } else {
                pixelWriter.setColor(x, y, pixelReader.getColor(x, y));
            }
        }
    }
    return newImage;
}
 
源代码6 项目: MyBox   文件: FxmlImageManufacture.java
public static Image horizontalImage(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();

    for (int j = 0; j < height; ++j) {
        int l = 0, r = width - 1;
        while (l <= r) {
            Color cl = pixelReader.getColor(l, j);
            Color cr = pixelReader.getColor(r, j);
            pixelWriter.setColor(l, j, cr);
            pixelWriter.setColor(r, j, cl);
            l++;
            r--;
        }
    }
    return newImage;
}
 
源代码7 项目: MyBox   文件: FxmlImageManufacture.java
public static Image verticalImage(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int i = 0; i < width; ++i) {
        int t = 0, b = height - 1;
        while (t <= b) {
            Color ct = pixelReader.getColor(i, t);
            Color cb = pixelReader.getColor(i, b);
            pixelWriter.setColor(i, t, cb);
            pixelWriter.setColor(i, b, ct);
            t++;
            b--;
        }
    }
    return newImage;
}
 
源代码8 项目: 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);
        }
    }
}
 
源代码9 项目: 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);
        }
    }
}
 
源代码10 项目: phoebus   文件: 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))));
}
 
源代码11 项目: phoebus   文件: 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();
}
 
源代码12 项目: 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);
}
 
@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;
}
 
@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);
    }
}
 
源代码15 项目: Medusa   文件: Helper.java
public static final 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() ? 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;
}
 
源代码16 项目: gef   文件: FXColorPicker.java
/**
 * Draws a color wheel into the given {@link WritableImage}, starting at the
 * given offsets, in the given size (in pixel).
 *
 * @param image
 *            The {@link WritableImage} in which the color wheel is drawn.
 * @param offsetX
 *            The horizontal offset (in pixel).
 * @param offsetY
 *            The vertical offset (in pixel).
 * @param size
 *            The size (in pixel).
 */
private void renderColorWheel(WritableImage image, int offsetX, int offsetY,
		int size) {
	PixelWriter px = image.getPixelWriter();
	double radius = size / 2;
	Point2D mid = new Point2D(radius, radius);
	for (int y = 0; y < size; y++) {
		for (int x = 0; x < size; x++) {
			double d = mid.distance(x, y);
			if (d <= radius) {
				// compute hue angle
				double angleRad = d == 0 ? 0
						: Math.atan2(y - mid.getY(), x - mid.getX());
				// compute saturation depending on distance to
				// middle
				// ([0;1])
				double sat = d / radius;
				Color color = Color.hsb(angleRad * 180 / Math.PI, sat, 1);
				px.setColor(offsetX + x, offsetY + y, color);
			} else {
				px.setColor(offsetX + x, offsetY + y, Color.TRANSPARENT);
			}
		}
	}
}
 
源代码17 项目: 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;
}
 
源代码18 项目: 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;
}
 
源代码19 项目: 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;
}
 
源代码20 项目: 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);
}
 
源代码21 项目: 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");
    }
}
 
源代码22 项目: 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;
    }
}
 
源代码23 项目: 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;
}
 
源代码24 项目: 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;
}
 
源代码25 项目: latexdraw   文件: ViewText.java
/**
 * Adds transparency to the given image.
 * @param img The image to transform.
 * @return The same image with white replaced by transparent.
 */
private WritableImage toTransparentPNG(final Image img) {
	final PixelReader pixelReader = img.getPixelReader();
	final WritableImage wImage = new WritableImage((int) img.getWidth(), (int) img.getHeight());
	final PixelWriter pixelWriter = wImage.getPixelWriter();

	for(int readY = 0; readY < img.getHeight(); readY++) {
		for(int readX = 0; readX < img.getWidth(); readX++) {
			final javafx.scene.paint.Color color = pixelReader.getColor(readX, readY);
			if (color.equals(javafx.scene.paint.Color.WHITE)) {
				pixelWriter.setColor(readX, readY, new javafx.scene.paint.Color(color.getRed(), color.getGreen(), color.getBlue(), 0)); // new javafx.scene.paint.Color(1, 1, 1, 0));
			} else {
				pixelWriter.setColor(readX, readY, color);
			}
		}
	}

	return wImage;
}
 
源代码26 项目: chart-fx   文件: ContourDataSetCache.java
protected WritableImage convertDataArrayToImage(final double[] inputData, final int dataWidth, final int dataHeight,
        final ColorGradient colorGradient) {
    final int length = dataWidth * dataHeight;

    final byte[] byteBuffer = ByteArrayCache.getInstance().getArrayExact(length * BGRA_BYTE_SIZE);
    final int rowSizeInBytes = BGRA_BYTE_SIZE * dataWidth;
    final WritableImage image = this.getImage(dataWidth, dataHeight);
    final PixelWriter pixelWriter = image.getPixelWriter();
    if (pixelWriter == null) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.atError().log("Could not get PixelWriter for image");
        }
        return image;
    }

    final int hMinus1 = dataHeight - 1;
    for (int yIndex = 0; yIndex < dataHeight; yIndex++) {
        final int rowIndex = dataWidth * yIndex;
        final int rowPixelIndex = rowSizeInBytes * (hMinus1 - yIndex);
        for (int xIndex = 0; xIndex < dataWidth; xIndex++) {
            final int x = xIndex;
            final int[] color = colorGradient.getColorBytes(inputData[rowIndex + xIndex]);

            final int pixelIndex = rowPixelIndex + x * BGRA_BYTE_SIZE;
            byteBuffer[pixelIndex] = (byte) (color[3]);
            byteBuffer[pixelIndex + 1] = (byte) (color[2]);
            byteBuffer[pixelIndex + 2] = (byte) (color[1]);
            byteBuffer[pixelIndex + 3] = (byte) (color[0]);
        }
    }

    pixelWriter.setPixels(0, 0, dataWidth, dataHeight, PixelFormat.getByteBgraPreInstance(), byteBuffer, 0,
            rowSizeInBytes);
    ByteArrayCache.getInstance().add(byteBuffer);
    return image;
}
 
源代码27 项目: oim-fx   文件: FindUserItem.java
private void setGrayImage(Image image) {
	PixelReader pixelReader = image.getPixelReader();
	grayImage = new WritableImage((int) image.getWidth(), (int) image.getHeight());
	PixelWriter pixelWriter = grayImage.getPixelWriter();

	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			Color color = pixelReader.getColor(x, y);
			color = color.grayscale();
			pixelWriter.setColor(x, y, color);
		}
	}
}
 
源代码28 项目: oim-fx   文件: ImageHandler.java
private void pixWithImage(int type) {
	PixelReader pixelReader = imageView.getImage().getPixelReader();
	// Create WritableImage
	wImage = new WritableImage((int) image.getWidth(),(int) image.getHeight());
	PixelWriter pixelWriter = wImage.getPixelWriter();

	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			Color color = pixelReader.getColor(x, y);
			switch (type) {
			case 0:
				color = color.brighter();
				break;
			case 1:
				color = color.darker();
				break;
			case 2:
				color = color.grayscale();
				break;
			case 3:
				color = color.invert();
				break;
			case 4:
				color = color.saturate();
				break;
			case 5:
				color = color.desaturate();
				break;
			default:
				break;
			}
			pixelWriter.setColor(x, y, color);
		}
	}
	imageView.setImage(wImage);
}
 
源代码29 项目: Quelea   文件: Utils.java
/**
 * Get an image filled with the specified colour.
 * <p/>
 * @param color the colour of the image.
 * @return the image.
 */
public static Image getImageFromColour(final Color color) {
	WritableImage image = new WritableImage(2, 2);
	PixelWriter writer = image.getPixelWriter();
	for (int i = 0; i < image.getWidth(); i++) {
		for (int j = 0; j < image.getHeight(); j++) {
			writer.setColor(i, j, color);
		}
	}
	return image;
}
 
源代码30 项目: mcaselector   文件: ImageHelper.java
public static void reloadEmpty() {
	WritableImage wImage = new WritableImage(Tile.SIZE, Tile.SIZE);
	PixelWriter pWriter = wImage.getPixelWriter();
	for (int x = 0; x < Tile.SIZE; x++) {
		for (int y = 0; y < Tile.SIZE; y++) {
			pWriter.setColor(x, y, Tile.EMPTY_COLOR.makeJavaFXColor());
		}
	}
	empty = wImage;
}
 
 类所在包
 同包方法