本文整理匯總了Java中javafx.scene.image.PixelWriter.setColor方法的典型用法代碼示例。如果您正苦於以下問題:Java PixelWriter.setColor方法的具體用法?Java PixelWriter.setColor怎麽用?Java PixelWriter.setColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.image.PixelWriter
的用法示例。
在下文中一共展示了PixelWriter.setColor方法的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);
}
}
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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;
}
示例6: 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);
}
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
}
示例10: 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;
}
示例11: createImage
import javafx.scene.image.PixelWriter; //導入方法依賴的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;
}
示例12: createNoiseImage
import javafx.scene.image.PixelWriter; //導入方法依賴的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;
}
示例13: createNoiseImage
import javafx.scene.image.PixelWriter; //導入方法依賴的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;
}
示例14: getHuesCircle
import javafx.scene.image.PixelWriter; //導入方法依賴的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;
}
示例15: FillHueCanvas
import javafx.scene.image.PixelWriter; //導入方法依賴的package包/類
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);
}