Here you can find the source of markImageBorders(final BufferedImage img, final int startW, final int startH)
Parameter | Description |
---|---|
img | the image to mark |
startW | the width from which to start marking |
startH | the height from which the marking starts |
protected static BufferedImage markImageBorders(final BufferedImage img, final int startW, final int startH)
//package com.java2s; //License from project: Open Source License import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { /**//from w w w . ja v a 2 s . co m * Fully marks the bottom and right borders of an image transparent (transparent white). Used in isEqual to mark the * previously not existent parts of an image. * * @param img * the image to mark * @param startW * the width from which to start marking * @param startH * the height from which the marking starts * @return the marked image */ protected static BufferedImage markImageBorders(final BufferedImage img, final int startW, final int startH) { final BufferedImage copy = copyImage(img); final Color markTransparentWhite = new Color(255, 255, 255, 0); final Graphics2D g = copy.createGraphics(); g.setColor(markTransparentWhite); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, 1.0f)); if (startW < copy.getWidth()) { g.fillRect(startW, 0, copy.getWidth() - startW, copy.getHeight()); } if (startH < copy.getHeight()) { g.fillRect(0, startH, copy.getWidth(), copy.getHeight() - startH); } g.dispose(); return copy; } /** * 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; } }