类javafx.scene.image.PixelReader源码实例Demo

下面列出了怎么用javafx.scene.image.PixelReader的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: chart-fx   文件: WriteFxImage.java
/**
 * copy the given Image to a WritableImage
 * 
 * @param image the input image
 * @return clone of image
 */
public static WritableImage clone(Image image) {
    int height = (int) image.getHeight();
    int width = (int) image.getWidth();
    WritableImage writableImage = WritableImageCache.getInstance().getImage(width, height);
    PixelWriter pixelWriter = writableImage.getPixelWriter();
    if (pixelWriter == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }

    final PixelReader pixelReader = image.getPixelReader();
    if (pixelReader == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            Color color = pixelReader.getColor(x, y);
            pixelWriter.setColor(x, y, color);
        }
    }
    return writableImage;
}
 
源代码2 项目: chart-fx   文件: WriteFxImage.java
public static void copyImageDataToPixelBuffer(final Image image, final int[] uncompressedImageData) {
    if (image == null) {
        throw new IllegalArgumentException("image is null");
    }
    final PixelReader pr = image.getPixelReader();
    if (pr == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }
    if (uncompressedImageData == null) {
        throw new IllegalArgumentException("uncompressedImageData is null");
    }
    final int w = (int) image.getWidth();
    final int h = (int) image.getHeight();
    final int requiredSize = w * h;
    if (uncompressedImageData.length < requiredSize) {
        throw new IllegalArgumentException("uncompressedImageData.length = " //
                                           + uncompressedImageData.length + " too small, should be at least" + requiredSize);
    }
    int i = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            uncompressedImageData[i++] = pr.getArgb(x, y);
        }
    }
}
 
源代码3 项目: chart-fx   文件: WriteFxImage.java
public static PaletteQuantizer estimatePalette(final Image image, final boolean alpha, final int nColors) {
    if (image == null) {
        throw new IllegalArgumentException(IMAGE_MUST_NOT_BE_NULL);
    }
    // get meta info
    final PixelReader pr = image.getPixelReader();
    if (pr == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }
    final int w = (int) image.getWidth();
    final int h = (int) image.getHeight();

    PaletteQuantizerNeuQuant cuant = new PaletteQuantizerNeuQuant(w, h, (x, y) -> pr.getArgb(y, x));
    cuant.setParReserveAlphaColor(alpha);
    cuant.setParNcolors(nColors);
    cuant.run();

    return cuant;
}
 
源代码4 项目: chart-fx   文件: FuzzyTestImageUtils.java
private static double comparePoorMansImageComparison(final Image img1, final Image img2) {
    final int width = (int) img1.getWidth();
    final int height = (int) img1.getHeight();
    if (width != (int) img2.getWidth() || height != (int) img2.getHeight()) {
        return 0.0;
    }
    final double nPixels = width * height;
    double diff = 1.0;
    final PixelReader pixelReaderRef = img1.getPixelReader();
    final PixelReader pixelReaderTest = img2.getPixelReader();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            diff *= 1.0 - (1.0 - pixelDiff(pixelReaderRef.getColor(x, y), pixelReaderTest.getColor(x, y))) / nPixels;
        }
    }
    return diff;
}
 
源代码5 项目: oim-fx   文件: HeadImagePanel.java
private void setGrayImage(Image image) {
	if (null != image && !image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			if (null != pixelWriter && null != pixelReader) {
				for (int y = 0; y < imageHeight; y++) {
					for (int x = 0; x < imageWidth; x++) {
						Color color = pixelReader.getColor(x, y);
						color = color.grayscale();
						pixelWriter.setColor(x, y, color);
					}
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
源代码6 项目: oim-fx   文件: HeadImageItemPane.java
private void setGrayImage(Image image) {
	if (null != image&&!image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
源代码7 项目: oim-fx   文件: ImagePane.java
private void setGrayImage(Image image) {
	if (null != image && !image.isBackgroundLoading()) {
		int imageWidth = (int) image.getWidth();
		int imageHeight = (int) image.getHeight();
		if (imageWidth > 0 && imageHeight > 0) {
			PixelReader pixelReader = image.getPixelReader();
			grayImage = new WritableImage(imageWidth, imageHeight);
			PixelWriter pixelWriter = grayImage.getPixelWriter();
			for (int y = 0; y < imageHeight; y++) {
				for (int x = 0; x < imageWidth; x++) {
					Color color = pixelReader.getColor(x, y);
					color = color.grayscale();
					pixelWriter.setColor(x, y, color);
				}
			}
		} else {
			grayImage = null;
		}
	} else {
		grayImage = null;
	}
}
 
源代码8 项目: MyBox   文件: ImageViewerController.java
@FXML
@Override
public void paneClicked(MouseEvent event) {
    if (paletteController == null || !paletteController.getParentController().equals(this)) {
        isPickingColor.set(false);
    }
    if (isPickingColor.get()) {
        IntPoint p = getImageXYint(event, imageView);
        if (p == null) {
            return;
        }
        PixelReader pixelReader = imageView.getImage().getPixelReader();
        Color color = pixelReader.getColor(p.getX(), p.getY());
        paletteController.setColor(color);
    } else {
        super.paneClicked(event);
    }
}
 
源代码9 项目: MyBox   文件: ImageMaskController.java
public DoublePoint showXY(MouseEvent event, DoublePoint p) {
    if (needNotCoordinates
            || !AppVariables.ImagePopCooridnate
            || xyText == null || !xyText.isVisible()) {
        return null;
    }
    if (p == null) {

        if (xyText != null) {
            xyText.setText("");
        }
        return null;
    }

    if (xyText != null && xyText.isVisible()) {
        PixelReader pixelReader = imageView.getImage().getPixelReader();
        Color color = pixelReader.getColor((int) p.getX(), (int) p.getY());
        String s = (int) Math.round(p.getX()) + "," + (int) Math.round(p.getY()) + "\n"
                + FxmlColor.colorDisplaySimple(color);
        xyText.setText(s);
        xyText.setX(event.getX() + 10);
        xyText.setY(event.getY());
    }
    return p;
}
 
源代码10 项目: MyBox   文件: ImageManufacturePaneController.java
@FXML
@Override
public void paneClicked(MouseEvent event) {
    if (isPickingColor.get()) {
        IntPoint p = getImageXYint(event, imageView);
        if (p == null) {
            return;
        }
        PixelReader pixelReader = imageView.getImage().getPixelReader();
        Color color = pixelReader.getColor(p.getX(), p.getY());
        colorPicked(color);

    } else if (scopeCommonBox.isDisabled()) {
        super.paneClicked(event);
        parent.operationController.paneClicked(event);

    } else if (scope != null && scope.getScopeType() != null) {
        paneClickedForScope(event);

    }

}
 
源代码11 项目: MyBox   文件: FxmlImageManufacture.java
public static Image cropInsideFx(Image image, DoubleShape shape, Color bgColor) {
    if (image == null || shape == null || !shape.isValid()
            || bgColor == null) {
        return image;
    }
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (shape.include(x, y)) {
                pixelWriter.setColor(x, y, bgColor);
            } else {
                pixelWriter.setColor(x, y, pixelReader.getColor(x, y));
            }
        }
    }
    return newImage;
}
 
源代码12 项目: MyBox   文件: FxmlImageManufacture.java
public static boolean sameImage(Image imageA, Image imageB) {
    if (imageA == null || imageB == null
            || imageA.getWidth() != imageB.getWidth()
            || imageA.getHeight() != imageB.getHeight()) {
        return false;
    }
    PixelReader readA = imageA.getPixelReader();
    PixelReader readB = imageB.getPixelReader();
    for (int y = 0; y < imageA.getHeight(); y++) {
        for (int x = 0; x < imageA.getWidth(); x++) {
            if (!readA.getColor(x, y).equals(readB.getColor(x, y))) {
                return false;
            }
        }
    }
    return true;
}
 
源代码13 项目: MyBox   文件: FxmlImageManufacture.java
public static Image horizontalImage(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();

    for (int j = 0; j < height; ++j) {
        int l = 0, r = width - 1;
        while (l <= r) {
            Color cl = pixelReader.getColor(l, j);
            Color cr = pixelReader.getColor(r, j);
            pixelWriter.setColor(l, j, cr);
            pixelWriter.setColor(r, j, cl);
            l++;
            r--;
        }
    }
    return newImage;
}
 
源代码14 项目: MyBox   文件: FxmlImageManufacture.java
public static Image verticalImage(Image image) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage(width, height);
    PixelWriter pixelWriter = newImage.getPixelWriter();
    for (int i = 0; i < width; ++i) {
        int t = 0, b = height - 1;
        while (t <= b) {
            Color ct = pixelReader.getColor(i, t);
            Color cb = pixelReader.getColor(i, b);
            pixelWriter.setColor(i, t, cb);
            pixelWriter.setColor(i, b, ct);
            t++;
            b--;
        }
    }
    return newImage;
}
 
源代码15 项目: charts   文件: HeatMap.java
/**
 * 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);
}
 
源代码16 项目: NinePatch   文件: FxNinePatch.java
@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;
}
 
源代码17 项目: gluon-samples   文件: Service.java
private INDArray fromImage(File image) {
    System.out.println("FROMImage called for "+image);
    Image im = new Image(image.toURI().toString(), width, height, false, true);
    PixelReader pr = im.getPixelReader();
    System.out.println("crated image, "+im.getWidth()+", "+im.getHeight());
    INDArray row = Nd4j.createUninitialized(width * height);
    boolean bw = pr.getColor(0, 0).getBrightness() < .5;
    System.out.println("bw = " + bw);
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int pixel = pr.getArgb(i, j);
            Color c = pr.getColor(i, j);
            // int red = ((pixel >> 16) & 0xff);
            //  int green = ((pixel >> 8) & 0xff);
            //  int blue = (pixel & 0xff);

            //   int grayLevel = (int) (0.2162 * (double) red + 0.7152 * (double) green + 0.0722 * (double) blue) / 3;
            //   grayLevel = (int)((red + green + blue)/3.);
            //   grayLevel = 255 - grayLevel; // Inverted the grayLevel value here.
            //  int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel;
            //    System.out.println("p[" + i + "][" + j + "]: " + pixel+" -> "+grayLevel+ "("+red+", "+green+", "+blue+")"+" -> "+c.getBrightness()+", "+c.getSaturation()+", "+c.getHue()+", "+c.getOpacity());
            row.putScalar(j * height + i, bw ? c.getBrightness() : 1 - c.getBrightness());
        }
    }
    return row;
}
 
源代码18 项目: FXTutorials   文件: BasicEncoder.java
@Override
public Image encode(Image image, String message) {
    int width = (int) image.getWidth();
    int height = (int) image.getHeight();

    WritableImage copy = new WritableImage(image.getPixelReader(), width, height);
    PixelWriter writer = copy.getPixelWriter();
    PixelReader reader = image.getPixelReader();

    boolean[] bits = encode(message);

    IntStream.range(0, bits.length)
            .mapToObj(i -> new Pair<>(i, reader.getArgb(i % width, i / width)))
            .map(pair -> new Pair<>(pair.getKey(), bits[pair.getKey()] ? pair.getValue() | 1 : pair.getValue() &~ 1))
            .forEach(pair -> {
                int x = pair.getKey() % width;
                int y = pair.getKey() / width;

                writer.setArgb(x, y, pair.getValue());
            });

    return copy;
}
 
源代码19 项目: FXTutorials   文件: DisintegrationApp.java
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();
}
 
源代码20 项目: jace   文件: Font.java
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();
}
 
源代码21 项目: Augendiagnose   文件: PupilAndIrisDetector.java
/**
 * Collect the information of all circles around the center.
 *
 * @param maxRelevantRadius The maximal circle radius considered
 */
private void collectCircleInfo(final int maxRelevantRadius) {
	PixelReader pixelReader = mImage.getPixelReader();
	int maxPossibleRadius = (int) Math.min(
			Math.min(mImage.getWidth() - 1 - mXCenter, mXCenter),
			Math.min(mImage.getHeight() - 1 - mYCenter, mYCenter));
	int maxRadius = Math.min(maxRelevantRadius, maxPossibleRadius);
	// For iris refinement, ignore points on top and bottom
	long maxRadius2 = (maxRadius + 1) * (maxRadius + 1);
	for (int x = mXCenter - maxRadius; x <= mXCenter + maxRadius; x++) {
		for (int y = mYCenter - maxRadius; y <= mYCenter + maxRadius; y++) {
			long d2 = (x - mXCenter) * (x - mXCenter) + (y - mYCenter) * (y - mYCenter);
			if (d2 <= maxRadius2) {
				int d = (int) Math.round(Math.sqrt(d2));
				float brightness = getBrightness(pixelReader.getColor(x, y));
				addInfo(d, brightness);
			}
		}
	}

}
 
源代码22 项目: latexdraw   文件: ViewText.java
/**
 * Adds transparency to the given image.
 * @param img The image to transform.
 * @return The same image with white replaced by transparent.
 */
private WritableImage toTransparentPNG(final Image img) {
	final PixelReader pixelReader = img.getPixelReader();
	final WritableImage wImage = new WritableImage((int) img.getWidth(), (int) img.getHeight());
	final PixelWriter pixelWriter = wImage.getPixelWriter();

	for(int readY = 0; readY < img.getHeight(); readY++) {
		for(int readX = 0; readX < img.getWidth(); readX++) {
			final javafx.scene.paint.Color color = pixelReader.getColor(readX, readY);
			if (color.equals(javafx.scene.paint.Color.WHITE)) {
				pixelWriter.setColor(readX, readY, new javafx.scene.paint.Color(color.getRed(), color.getGreen(), color.getBlue(), 0)); // new javafx.scene.paint.Color(1, 1, 1, 0));
			} else {
				pixelWriter.setColor(readX, readY, color);
			}
		}
	}

	return wImage;
}
 
源代码23 项目: OpenLabeler   文件: OpenCVUtils.java
/**
 * Return OpenCV MAT in CvType.CV_8UC4
 */
public static Mat imageToMat(Image image) {
   int width = (int) image.getWidth();
   int height = (int) image.getHeight();
   byte[] buffer = new byte[width * height * 4];

   PixelReader reader = image.getPixelReader();
   WritablePixelFormat<ByteBuffer> format = WritablePixelFormat.getByteBgraInstance();
   reader.getPixels(0, 0, width, height, format, buffer, 0, width * 4);

   Mat mat = new Mat(height, width, CvType.CV_8UC4);
   mat.put(0, 0, buffer);
   return mat;
}
 
源代码24 项目: chart-fx   文件: MapGenerator.java
/**
 * You will have to supply an object that will create the Hexagons as you like. E.g.
 * <p>
 * class HexagonCreator implements IHexagonCreator {
 *
 * @param creator the object that will actually create the Hexagon.
 * @Override public void createHexagon(GridPosition position, javafx.scene.paint.Color color) { Hexagon h = new
 *           Hexagon(position, 20, 0, 0); h.setBackgroundColor(color); map.addHexagon(h); } }
 */
public void generate(IHexagonCreator creator) {
    final PixelReader pr = image.getPixelReader();
    if (pr == null) {
        return;
    }
    final double imageWidth = image.getWidth();
    final double imageHeight = image.getHeight();
    final double hexagonMapWidthInPixels = map.getGraphicsHorizontalDistanceBetweenHexagons() * mapWidth;
    horizontalRelation = imageWidth / hexagonMapWidthInPixels;
    final double estimatedHexagonMapHeightInPixels = imageHeight / horizontalRelation;

    final int mapHeight = (int) (estimatedHexagonMapHeightInPixels
                                 / map.getGraphicsverticalDistanceBetweenHexagons());
    verticalRelation = imageHeight
                       / (map.getGraphicsverticalDistanceBetweenHexagons() * mapHeight + map.getGraphicsHexagonHeight() / 2);
    // Not really sure about the last part but it seems to work. And should I make the corresponding correction on
    // the horizontalRelation ?

    for (int x = 0; x < mapWidth; x++) {
        for (int y = 0; y < mapHeight; y++) {
            final int axialQ = x - (y - (y & 1)) / 2;
            final int axialR = y;
            final Hexagon h = new Hexagon(axialQ, axialR);
            h.setMap(map);
            final int xOnImage = (int) ((h.getGraphicsXoffset() - map.graphicsXpadding) * horizontalRelation);
            final int yOnImage = (int) ((h.getGraphicsYoffset() - map.graphicsYpadding) * verticalRelation);
            final Color pixelColor = pr.getColor(xOnImage, yOnImage);
            creator.createHexagon(axialQ, axialR, pixelColor, map);
        }
    }
}
 
源代码25 项目: chart-fx   文件: WriteFxImage.java
/**
 * Encodes a JavaFx image as an RGB png image. If you pass in a ByteBuffer to
 * use, please make sure that it has enough capacity to fit the encoded image or
 * handle errors (IndexOutOfBoundsException) accordingly. If you want to be on
 * the safe side, use {@link #getCompressedSizeBound(int, int, boolean)
 * getCompressedSizeBound(width, height, alpha)} to get an upper bound for the
 * output size.
 *
 * @param image            The input image to be encoded
 * @param byteBuffer       optional byte buffer to store the output in, pass
 *                         null to return a new one.
 * @param alpha            whether to include alpha information in the image
 * @param compressionLevel {@link Deflater#BEST_COMPRESSION} (9) to
 *                         {@link Deflater#BEST_SPEED} (0)
 * @param metaInfo         an optional map which will be filled with debugging
 *                         information like compression efficiency
 * @return a byte buffer with the encoded image
 * @see "https://tools.ietf.org/html/rfc2083"
 */
public static ByteBuffer encodeAlt(final Image image, final ByteBuffer byteBuffer, final boolean alpha, final int compressionLevel, final Map<String, Object> metaInfo) {
    if (image == null) {
        throw new IllegalArgumentException(IMAGE_MUST_NOT_BE_NULL);
    }
    // get meta info
    // get necessary helper classes
    final PixelReader pr = image.getPixelReader();
    if (pr == null) {
        throw new IllegalStateException(IMAGE_PIXEL_READER_NOT_AVAILABLE);
    }
    final int w = (int) image.getWidth();
    final int h = (int) image.getHeight();

    // allocate output buffer if necessary. conservative allocation, assume upper
    // bound for deflate algorithm
    final ByteBuffer outputByteBuffer = byteBuffer == null ? ByteBuffer.allocate(getCompressedSizeBound(w, h, alpha)) : byteBuffer;
    final CRC32 crc = new CRC32();
    final Deflater compressor = new Deflater(compressionLevel);
    // actual PNG encoding
    writeImageHeader(w, h, alpha, outputByteBuffer, crc);
    writeImageData(pr, w, h, alpha, compressor, outputByteBuffer, crc);
    writeImageFooter(outputByteBuffer, crc);
    // prepare to return outputBuffer
    outputByteBuffer.flip();
    // DEGBUG output
    if (metaInfo != null) {
        final int bytesPerPixel = alpha ? 4 : 3;
        metaInfo.put("bufferSize", outputByteBuffer.capacity());
        metaInfo.put("outputSizeBound", getCompressedSizeBound(w, h, alpha));
        metaInfo.put("compression", (double) compressor.getBytesWritten() / (w * h * bytesPerPixel));
        metaInfo.put("width", w);
        metaInfo.put("height", h);
        metaInfo.put("colorMode", alpha ? "rgba" : "rgb");
        metaInfo.put("compressionLevel", compressionLevel);
        metaInfo.put("outputSize", outputByteBuffer.limit() - outputByteBuffer.position());
    }
    return outputByteBuffer;
}
 
源代码26 项目: oim-fx   文件: FindUserItem.java
private void setGrayImage(Image image) {
	PixelReader pixelReader = image.getPixelReader();
	grayImage = new WritableImage((int) image.getWidth(), (int) image.getHeight());
	PixelWriter pixelWriter = grayImage.getPixelWriter();

	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			Color color = pixelReader.getColor(x, y);
			color = color.grayscale();
			pixelWriter.setColor(x, y, color);
		}
	}
}
 
源代码27 项目: oim-fx   文件: ImageHandler.java
private void pixWithImage(int type) {
	PixelReader pixelReader = imageView.getImage().getPixelReader();
	// Create WritableImage
	wImage = new WritableImage((int) image.getWidth(),(int) image.getHeight());
	PixelWriter pixelWriter = wImage.getPixelWriter();

	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			Color color = pixelReader.getColor(x, y);
			switch (type) {
			case 0:
				color = color.brighter();
				break;
			case 1:
				color = color.darker();
				break;
			case 2:
				color = color.grayscale();
				break;
			case 3:
				color = color.invert();
				break;
			case 4:
				color = color.saturate();
				break;
			case 5:
				color = color.desaturate();
				break;
			default:
				break;
			}
			pixelWriter.setColor(x, y, color);
		}
	}
	imageView.setImage(wImage);
}
 
源代码28 项目: MyBox   文件: FxmlImageManufacture.java
public static Image manufactureImage(Image image, int manuType) {
    PixelReader pixelReader = image.getPixelReader();
    WritableImage newImage = new WritableImage((int) image.getWidth(), (int) image.getHeight());
    PixelWriter pixelWriter = newImage.getPixelWriter();

    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            Color color = pixelReader.getColor(x, y);
            switch (manuType) {
                case ImageManufactureType.Brighter:
                    color = color.brighter();
                    break;
                case ImageManufactureType.Darker:
                    color = color.darker();
                    break;
                case ImageManufactureType.Gray:
                    color = color.grayscale();
                    break;
                case ImageManufactureType.Invert:
                    color = color.invert();
                    break;
                case ImageManufactureType.Saturate:
                    color = color.saturate();
                    break;
                case ImageManufactureType.Desaturate:
                    color = color.desaturate();
                    break;
                default:
                    break;
            }
            pixelWriter.setColor(x, y, color);
        }
    }
    return newImage;
}
 
源代码29 项目: MyBox   文件: FxmlImageManufacture.java
public static Image cropOutsideFx(Image image, DoubleShape shape, Color bgColor) {
    try {
        if (image == null || shape == null || !shape.isValid()
                || bgColor == null) {
            return image;
        }
        int width = (int) image.getWidth();
        int height = (int) image.getHeight();
        DoubleRectangle bound = shape.getBound();

        int x1 = (int) Math.round(Math.max(0, bound.getSmallX()));
        int y1 = (int) Math.round(Math.max(0, bound.getSmallY()));
        if (x1 >= width || y1 >= height) {
            return image;
        }
        int x2 = (int) Math.round(Math.min(width - 1, bound.getBigX()));
        int y2 = (int) Math.round(Math.min(height - 1, bound.getBigY()));
        int w = x2 - x1 + 1;
        int h = y2 - y1 + 1;
        PixelReader pixelReader = image.getPixelReader();
        WritableImage newImage = new WritableImage(w, h);
        PixelWriter pixelWriter = newImage.getPixelWriter();
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                if (shape.include(x1 + x, y1 + y)) {
                    pixelWriter.setColor(x, y, pixelReader.getColor(x1 + x, y1 + y));
                } else {
                    pixelWriter.setColor(x, y, bgColor);
                }
            }
        }
        return newImage;
    } catch (Exception e) {
        logger.debug(e.toString());
        return image;
    }
}
 
源代码30 项目: MyBox   文件: FxmlImageManufacture.java
public static Image dragMarginsFx(Image image, Color color, DoubleRectangle rect) {
    try {
        if (image == null || rect == null) {
            return image;
        }
        int iwidth = (int) image.getWidth();
        int iheight = (int) image.getHeight();

        int rwidth = (int) rect.getWidth();
        int rheight = (int) rect.getHeight();
        int rx = (int) rect.getSmallX();
        int ry = (int) rect.getSmallY();
        PixelReader pixelReader = image.getPixelReader();
        WritableImage newImage = new WritableImage(rwidth, rheight);
        PixelWriter pixelWriter = newImage.getPixelWriter();
        int ix, iy;
        for (int j = 0; j < rheight; ++j) {
            for (int i = 0; i < rwidth; ++i) {
                ix = i + rx;
                iy = j + ry;
                if (ix >= 0 && ix < iwidth && iy >= 0 && iy < iheight) {
                    pixelWriter.setColor(i, j, pixelReader.getColor(ix, iy));
                } else {
                    pixelWriter.setColor(i, j, color);
                }
            }
        }

        return newImage;

    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }

}
 
 类所在包
 同包方法