当前位置: 首页>>代码示例>>Java>>正文


Java PixelWriter类代码示例

本文整理汇总了Java中javafx.scene.image.PixelWriter的典型用法代码示例。如果您正苦于以下问题:Java PixelWriter类的具体用法?Java PixelWriter怎么用?Java PixelWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PixelWriter类属于javafx.scene.image包,在下文中一共展示了PixelWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderImage

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:ImageOperatorSample.java

示例2: updateColorBar

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
/** 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))));
}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:23,代码来源:ColorMapDialog.java

示例3: resizeCanvas

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
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;
}
 
开发者ID:RPTools,项目名称:tokentool,代码行数:20,代码来源:ImageUtil.java

示例4: updateHeatMap

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
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);
}
 
开发者ID:HanSolo,项目名称:worldheatmap,代码行数:26,代码来源:SimpleHeatMap.java

示例5: updateHeatMap

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:HanSolo,项目名称:worldheatmap,代码行数:26,代码来源:HeatMap.java

示例6: updateHeatMap

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:28,代码来源:HeatMap.java

示例7: validate

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
@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;
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:22,代码来源:SingleColorTextureFileCreator.java

示例8: writeData

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:26,代码来源:SingleColorTextureFileCreator.java

示例9: copy

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
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))));
}
 
开发者ID:InfinityStudio,项目名称:minecraft-jfx-skin,代码行数:17,代码来源:SkinHelper.java

示例10: getImage

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
@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;
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:20,代码来源:WriteSingleColorImageTestBase.java

示例11: getImage

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
@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;
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:18,代码来源:WriteSingleARGBImageTestBase.java

示例12: createNoiseImage

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
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;
}
 
开发者ID:HanSolo,项目名称:Medusa,代码行数:21,代码来源:Helper.java

示例13: renderLayer

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:DarkLBP,项目名称:Krothium-Launcher,代码行数:27,代码来源:TexturePreview.java

示例14: resampleImage

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:DarkLBP,项目名称:Krothium-Launcher,代码行数:28,代码来源:Kernel.java

示例15: colorizeImage

import javafx.scene.image.PixelWriter; //导入依赖的package包/类
/**
   * 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;
  }
 
开发者ID:macjuul,项目名称:blasteroids,代码行数:25,代码来源:RenderUtils.java


注:本文中的javafx.scene.image.PixelWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。