Here you can find the source of drawBorders(final BufferedImage image, final int currentX, final int currentY, final int width, final int height, final int subImageWidth, final int subImageHeight, final Color c)
Parameter | Description |
---|---|
image | The image in which something will be marked |
currentX | Starting position |
currentY | Starting position |
width | Vertical length of the rectangle to mark |
height | Horizontal length of the rectangle to mark |
subImageWidth | the width of the partial image |
subImageHeight | the height of the partial image |
protected static void drawBorders(final BufferedImage image, final int currentX, final int currentY, final int width, final int height, final int subImageWidth, final int subImageHeight, final Color c)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.image.BufferedImage; public class Main { /**/* w ww . j a v a 2 s . c om*/ * Colors the borders of a certain rectangle. Used to mark blocks. Uses the colorPixel method and subImageHeight/ * subImageWidth. <br> * Works directly on imgOut. * * @param image * The image in which something will be marked * @param currentX * Starting position * @param currentY * Starting position * @param width * Vertical length of the rectangle to mark * @param height * Horizontal length of the rectangle to mark * @param subImageWidth the width of the partial image * @param subImageHeight the height of the partial image */ protected static void drawBorders(final BufferedImage image, final int currentX, final int currentY, final int width, final int height, final int subImageWidth, final int subImageHeight, final Color c) { int x, y; for (int a = 0; a < subImageWidth; a++) { x = currentX * width + a; y = currentY * height; colorPixel(image, x, y, c); y = currentY * height + subImageHeight - 1; colorPixel(image, x, y, c); } for (int b = 1; b < subImageHeight - 1; b++) { x = currentX * width; y = currentY * height + b; colorPixel(image, x, y, c); x = currentX * width + subImageWidth - 1; colorPixel(image, x, y, c); } } /** * Colors a certain pixel using getComplementaryColor. Works directly on imgOut. * * @param x * the x coordinate of the pixel to color * @param y * the y coordinate of the pixel to color */ protected static void colorPixel(final BufferedImage image, final int x, final int y, final Color c) { Color newColor; if (c == null) { final Color currentColor = new Color(image.getRGB(x, y)); final double redLimit = 0.8; final int nonRedSum = currentColor.getGreen() + currentColor.getBlue(); final double results = nonRedSum > 0 ? currentColor.getRed() / nonRedSum : 0; if (results > redLimit) { // red is strong in that one newColor = Color.GREEN; } else { newColor = Color.RED; } } else { newColor = c; } image.setRGB(x, y, newColor.getRGB()); } }