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


Java PixelReader类代码示例

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


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

示例1: resizeCanvas

import javafx.scene.image.PixelReader; //导入依赖的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

示例2: 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;
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:22,代码来源:ImageTransformation.java

示例3: 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);
}
 
开发者ID:HanSolo,项目名称:worldheatmap,代码行数:26,代码来源:SimpleHeatMap.java

示例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);
    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

示例5: 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);
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:28,代码来源:HeatMap.java

示例6: Face

import javafx.scene.image.PixelReader; //导入依赖的package包/类
public Face(Image image, int startX, int startY, int width, int height, int interval, boolean reverseX, boolean reverseY,
		Supplier<Box> supplier, BiConsumer<Box, Point2D> consumer) {
	PixelReader reader = image.getPixelReader();
	for (int x = 0; x < width; x++)
		for (int y = 0; y < height; y++) {
			int argb;
			if ((argb = reader.getArgb(startX + (reverseX ? width - x - 1 : x) * interval,
					startY + (reverseY ? height - y - 1 : y) * interval)) != 0) {
				Box pixel = supplier.get();
				consumer.accept(pixel, new Point2D(x, y));
				pixel.setMaterial(createMaterial(Color.rgb(
						(argb >> 16) & 0xFF, (argb >> 8) & 0xFF, (argb >> 0) & 0xFF)));
				getChildren().add(pixel);
			}
		}
}
 
开发者ID:InfinityStudio,项目名称:minecraft-jfx-skin,代码行数:17,代码来源:SkinMultipleCubes.java

示例7: copy

import javafx.scene.image.PixelReader; //导入依赖的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

示例8: getPixels

import javafx.scene.image.PixelReader; //导入依赖的package包/类
@Override
public int[] getPixels(Image img, int x, int y, int w, int h)
{
    int[] pixels = new int[w * h];

    PixelReader reader = img.getPixelReader();

    PixelFormat.Type type =  reader.getPixelFormat().getType();

    WritablePixelFormat<IntBuffer> format = null;

    if(type == PixelFormat.Type.INT_ARGB_PRE)
    {
        format = PixelFormat.getIntArgbPreInstance();
    }
    else
    {
        format = PixelFormat.getIntArgbInstance();
    }

    reader.getPixels(x, y, w, h, format, pixels, 0, w);

    return pixels;
}
 
开发者ID:freeseawind,项目名称:NinePatch,代码行数:25,代码来源:FxNinePatch.java

示例9: get

import javafx.scene.image.PixelReader; //导入依赖的package包/类
public static Image get(String key, int tileX, int tileY) {
    if (!sheets.containsKey(key)) {
        throw new AssertionError("image does not exist");
    }
    
    // try to get image from cache
    if (tiles.get(key)[tileX][tileY] != null) {
        return tiles.get(key)[tileX][tileY];
    }
    
    // generate new image from sheet
    PixelReader reader = sheets.get(key).getPixelReader();
    WritableImage newImage = new WritableImage(reader, (WIDTH + MARGIN) * tileX, (HEIGHT + MARGIN) * tileY, WIDTH,
            HEIGHT);
            
    // put new image in cache
    tiles.get(key)[tileX][tileY] = newImage;
    
    return newImage;
    
}
 
开发者ID:GlassWispInteractive,项目名称:fictional-spoon,代码行数:22,代码来源:Tiles.java

示例10: 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;
    }
}
 
开发者ID:DarkLBP,项目名称:Krothium-Launcher,代码行数:27,代码来源:TexturePreview.java

示例11: resampleImage

import javafx.scene.image.PixelReader; //导入依赖的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

示例12: 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;
  }
 
开发者ID:macjuul,项目名称:blasteroids,代码行数:25,代码来源:RenderUtils.java

示例13: update

import javafx.scene.image.PixelReader; //导入依赖的package包/类
public void update(Path2D p2d) {
    setPath(resultpath, p2d);
    Path p = makePath();
    WritableImage wimg = new WritableImage(TESTW, TESTH);
    renderPath(p2d, p, wimg);
    PixelReader pr = wimg.getPixelReader();
    GraphicsContext gc = resultcv.getGraphicsContext2D();
    gc.save();
    for (int y = 0; y < TESTH; y++) {
        for (int x = 0; x < TESTW; x++) {
            boolean inpath = p2d.contains(x + 0.5, y + 0.5);
            boolean nearpath = near(p2d, x + 0.5, y + 0.5, warn);
            int pixel = pr.getArgb(x, y);
            renderPixelStatus(gc, x, y, pixel, inpath, nearpath);
        }
    }
    gc.restore();
}
 
开发者ID:bourgesl,项目名称:marlin-fx,代码行数:19,代码来源:TestNonAARasterization.java

示例14: transferPixels

import javafx.scene.image.PixelReader; //导入依赖的package包/类
/**
 * Transfer pixels from the rendering buffer to the winner/alpha maps.
 *
 * @param img Rendering buffer
 * @param x1 Left
 * @param x2 Right
 * @param y1 Bottom
 * @param y2 Top
 * @param layer Output array
 * @param c Entity number
 */
public void transferPixels(WritableImage img, int x1, int x2, int y1, int y2, int[][] layer, int c) {
  assert (c > 0);
  PixelReader reader = img.getPixelReader();
  for(int y = y1, py = 0; y < y2; y++, py++) {
    final int[] rowy = layer[y];
    for(int x = x1, px = 0; x < x2; x++, px++) {
      int col = reader.getArgb(px, py);
      int alpha = (col & 0xFF);
      // Always ignore cover less than 10%
      if(alpha < 0x19) {
        continue;
      }
      // Clip value range to positive bytes,
      // alpha = alpha > 0x7F ? 0x7F : alpha;
      int oldalpha = rowy[x] >>> 24;
      if(alpha == 0xFF || alpha >= oldalpha) {
        rowy[x] = (alpha << 24) | c;
      }
    }
  }
}
 
开发者ID:kno10,项目名称:reversegeocode,代码行数:33,代码来源:BuildLayeredIndexSliced.java

示例15: transferPixels

import javafx.scene.image.PixelReader; //导入依赖的package包/类
/**
 * Transfer pixels from the rendering buffer to the winner/alpha maps.
 *
 * @param img
 *            Rendering buffer
 * @param x1
 *            Left
 * @param x2
 *            Right
 * @param y1
 *            Bottom
 * @param y2
 *            Top
 * @param winner
 *            Output array
 * @param c
 *            Entity number
 */
public void transferPixels(WritableImage img, int x1, int x2, int y1,
		int y2, int[][] winner, int c) {
	PixelReader reader = img.getPixelReader();
	for (int y = y1, py = 0; y < y2; y++, py++) {
		for (int x = x1, px = 0; x < x2; x++, px++) {
			int col = reader.getArgb(px, py);
			int alpha = (col & 0xFF);
			// Always ignore cover less than 10%
			if (alpha < 0x19) {
				continue;
			}
			// Clip value range to positive bytes,
			alpha = alpha > 0x7F ? 0x7F : alpha;
			byte oldalpha = (byte) (winner[y][x] >>> 24);
			if (alpha == 0x7F || (alpha > 0 && alpha >= oldalpha)) {
				winner[y][x] = (alpha << 24) | c;
			}
		}
	}
}
 
开发者ID:kno10,项目名称:reversegeocode,代码行数:39,代码来源:BuildLayeredIndex.java


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