Here you can find the source of markDifferencesWithAMarker(final BufferedImage image, final Point[] pixels, final int markingSizeX, final int markingSizeY)
Parameter | Description |
---|---|
image | the original image for which the differences were found |
pixels | the array with the differences. |
markingSizeX | Length of the marker on the x axis |
markingSizeY | Length of the marker on the y axis |
protected static BufferedImage markDifferencesWithAMarker(final BufferedImage image, final Point[] pixels, final int markingSizeX, final int markingSizeY)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.image.BufferedImage; public class Main { /**/*from ww w . j a v a 2 s .c o m*/ * Method to mark areas around the detected differences. Goes through every pixel that was different and marks the * marking block it is in, unless it was marked already. <br> * If markingX of markingY are 1, it will simply mark the detected differences. * * @param image the original image for which the differences were found * @param pixels * the array with the differences. * @param markingSizeX Length of the marker on the x axis * @param markingSizeY Length of the marker on the y axis * @return Copy of the original image with marked pixels */ protected static BufferedImage markDifferencesWithAMarker(final BufferedImage image, final Point[] pixels, final int markingSizeX, final int markingSizeY) { if (pixels == null) { return null; } final BufferedImage imageCopy = copyImage(image); final Color highlighterColor = new Color(228, 252, 90, 50); final Color pixelEmphasizeColor = new Color(228, 0, 0); final Graphics2D g = imageCopy.createGraphics(); g.setColor(highlighterColor); for (final Point pixel : pixels) { // the middle of the block should be our pixel to make it marker like int x = pixel.x - (markingSizeX / 2); int y = pixel.y - (markingSizeY / 2); // avoid negative values x = x < 0 ? 0 : x; y = y < 0 ? 0 : y; g.fillRect(x, y, markingSizeX, markingSizeY); } g.dispose(); // mark the pixels on the new background for (final Point pixel : pixels) { imageCopy.setRGB(pixel.x, pixel.y, pixelEmphasizeColor.getRGB()); } return imageCopy; } /** * Creates another image, which is a copy of the source image * * @param source * the image to copy * @return a copy of that image as <b>BufferedImage</b> */ protected static BufferedImage copyImage(final BufferedImage source) { // Creates a fresh BufferedImage that has the same size and content of // the source image // if source has an image type of 0 set ARGB as type int imageType = source.getType(); if (imageType == 0) { imageType = BufferedImage.TYPE_INT_ARGB; } final BufferedImage copy = new BufferedImage(source.getWidth(), source.getHeight(), imageType); final Graphics g = copy.getGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); return copy; } }