本文整理汇总了Java中javafx.scene.image.PixelReader.getColor方法的典型用法代码示例。如果您正苦于以下问题:Java PixelReader.getColor方法的具体用法?Java PixelReader.getColor怎么用?Java PixelReader.getColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.image.PixelReader
的用法示例。
在下文中一共展示了PixelReader.getColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMask
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
@Override
public Set<Point2D> getMask(Image image, Color color) {
PixelReader pixelReader = image.getPixelReader();
Set<Point2D> mask = new HashSet<>();
int pixel;
boolean isTransparent, isBackgroundColor;
for(int i =0; i < image.getWidth(); i++){
for(int j = 0; j < image.getHeight(); j++){
pixel = pixelReader.getArgb(i, j);
//check the transparency of the pixel at (i,j)
isTransparent = (pixel >> 24) == 0x00;
Color backgroundColor = pixelReader.getColor(i, j);
isBackgroundColor = (color.equals(backgroundColor));
if(!isTransparent && !isBackgroundColor){
Point2D p = new Point2D(i,j);
mask.add(p);
}
}
}
return mask;
}
示例2: updateHeatMap
import javafx.scene.image.PixelReader; //导入方法依赖的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.PixelReader; //导入方法依赖的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.PixelReader; //导入方法依赖的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: renderLayer
import javafx.scene.image.PixelReader; //导入方法依赖的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;
}
}
示例6: colorizeImage
import javafx.scene.image.PixelReader; //导入方法依赖的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;
}
示例7: disintegrate
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
private void disintegrate(Image image) {
PixelReader pixelReader = image.getPixelReader();
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
Color color = pixelReader.getColor(x, y);
if (!color.equals(Color.TRANSPARENT)) {
Particle p = new Particle(x + 700, y + 50, color);
particles.add(p);
}
}
}
fullSize = particles.size();
}
示例8: _checkEnvironment
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
private int _checkEnvironment(Image image)
{
PixelReader reader = image.getPixelReader();
int width = (int) image.getWidth();
int height = (int) image.getHeight();
Color color;
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
color = reader.getColor(x, y);
if(color.getRed() == 0.0 && color.getGreen() == 0.0 && color.getGreen() == 0.0)
{
return 0;
}
}
}
return 1;
}
示例9: initalize
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
private static void initalize() {
initialized = true;
font = new int[256][8];
Thread fontLoader = new Thread(() -> {
InputStream in = Font.class.getClassLoader().getResourceAsStream("jace/data/font.png");
Image image = new Image(in);
PixelReader reader = image.getPixelReader();
for (int i = 0; i < 256; i++) {
int x = (i >> 4) * 13 + 2;
int y = (i & 15) * 13 + 4;
for (int j = 0; j < 8; j++) {
int row = 0;
for (int k = 0; k < 7; k++) {
Color color = reader.getColor((7 - k) + x, j + y);
boolean on = color.getRed() != 0;
row = (row << 1) | (on ? 0 : 1);
}
font[i][j] = row;
}
}
});
fontLoader.start();
}
示例10: clipImageWithMask
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
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;
}
示例11: processMagenta
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
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;
}
示例12: send
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
/**
* Send the image to the screen.
*
* @param image An image of size 960 x 160 pixel
*/
public void send (final Image image)
{
if (this.handle == null)
return;
final ByteBuffer header = ByteBuffer.allocateDirect (HDR_SZ);
final ByteBuffer buffer = ByteBuffer.allocateDirect (DATA_SZ);
final IntBuffer transfered = IntBuffer.allocate (1);
header.put (DISPLAY_HEADER);
final PixelReader reader = image.getPixelReader ();
for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
final Color color = reader.getColor (x, y);
// 3b(low) green - 5b red / 5b blue - 3b (high) green, e.g. gggRRRRR BBBBBGGG
final int red = (int) Math.round (color.getRed () * 31);
final int green = (int) Math.round (color.getGreen () * 63);
final int blue = (int) Math.round (color.getBlue () * 31);
buffer.put ((byte) ((green & 0x07) << 5 | red & 0x1F));
buffer.put ((byte) ((blue & 0x1F) << 3 | (green & 0x38) >> 3));
}
for (int x = 0; x < 128; x++)
buffer.put ((byte) 0x00);
}
LibUsb.bulkTransfer (this.handle, (byte) 0x01, header, transfered, 1000L);
LibUsb.bulkTransfer (this.handle, (byte) 0x01, buffer, transfered, 1000L);
}
示例13: renderLayerInverse
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
/**
* Renders a layer inversed
* @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 renderLayerInverse(int dstx, int dsty, int w, int h, PixelReader pr, PixelWriter pw, int srcx, int srcy) {
int x_origin = dstx;
for (int y = srcy; y < srcy + h; y++){
for (int x = srcx + w - 1; x >= srcx; x--) {
Color c = pr.getColor(x, y);
pw.setColor(dstx, dsty, c);
dstx++;
}
dsty++;
dstx = x_origin;
}
}
示例14: testAAAWarmup
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
@Test
public void testAAAWarmup() {
Image src = new Image("file:/Users/amo/Pictures/April_Mai/DSCF5453.jpg");
PixelReader reader = src.getPixelReader();
int width = (int) src.getWidth();
int height = (int) src.getHeight();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 2; 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);
}
}
}
}
示例15: testSetColor
import javafx.scene.image.PixelReader; //导入方法依赖的package包/类
@Test
public void testSetColor() {
Image src = new Image("file:/Users/amo/Pictures/April_Mai/DSCF5453.jpg");
PixelReader reader = src.getPixelReader();
int width = (int) src.getWidth();
int height = (int) src.getHeight();
long startTime = System.currentTimeMillis();
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);
}
}
}
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
System.out.println(elapsedTime + " ms");
}