Here you can find the source of drawBorder(BufferedImage originalImage, Color borderColor, int borderWidth)
public static BufferedImage drawBorder(BufferedImage originalImage, Color borderColor, int borderWidth)
//package com.java2s; /** This file is part of Approach Avoidance Task. * * Approach Avoidance Task is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version./*w w w .jav a2s.c om*/ * * Approach Avoidance Task is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Approach Avoidance Task. If not, see <http://www.gnu.org/licenses/>. * */ import java.awt.*; import java.awt.image.BufferedImage; public class Main { public static BufferedImage drawBorder(BufferedImage originalImage, Color borderColor, int borderWidth) { BufferedImage bi = new BufferedImage(originalImage.getWidth() + (2 * borderWidth), originalImage.getHeight() + (2 * borderWidth), BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.setColor(borderColor); g.drawImage(originalImage, borderWidth, borderWidth, null); BasicStroke stroke = new BasicStroke(borderWidth * 2); g.setStroke(stroke); g.drawRect(0, 0, bi.getWidth(), bi.getHeight()); g.dispose(); return bi; } }