本文整理汇总了Java中javafx.scene.image.WritableImage.getPixelWriter方法的典型用法代码示例。如果您正苦于以下问题:Java WritableImage.getPixelWriter方法的具体用法?Java WritableImage.getPixelWriter怎么用?Java WritableImage.getPixelWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.image.WritableImage
的用法示例。
在下文中一共展示了WritableImage.getPixelWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderImage
import javafx.scene.image.WritableImage; //导入方法依赖的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);
}
}
}
示例2: updateColorBar
import javafx.scene.image.WritableImage; //导入方法依赖的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))));
}
示例3: resizeCanvas
import javafx.scene.image.WritableImage; //导入方法依赖的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;
}
示例4: updateHeatMap
import javafx.scene.image.WritableImage; //导入方法依赖的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);
}
示例5: updateHeatMap
import javafx.scene.image.WritableImage; //导入方法依赖的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);
}
示例6: updateHeatMap
import javafx.scene.image.WritableImage; //导入方法依赖的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);
}
示例7: validate
import javafx.scene.image.WritableImage; //导入方法依赖的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;
}
示例8: writeData
import javafx.scene.image.WritableImage; //导入方法依赖的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);
}
}
示例9: getImage
import javafx.scene.image.WritableImage; //导入方法依赖的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;
}
示例10: getImage
import javafx.scene.image.WritableImage; //导入方法依赖的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;
}
示例11: createNoiseImage
import javafx.scene.image.WritableImage; //导入方法依赖的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;
}
示例12: resampleImage
import javafx.scene.image.WritableImage; //导入方法依赖的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;
}
示例13: createImage
import javafx.scene.image.WritableImage; //导入方法依赖的package包/类
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;
}
示例14: createNoiseImage
import javafx.scene.image.WritableImage; //导入方法依赖的package包/类
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;
}
示例15: getHuesCircle
import javafx.scene.image.WritableImage; //导入方法依赖的package包/类
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;
}