Java examples for Swing:Border
Adds a two colored border to the given image.
//package com.java2s; import java.awt.*; import java.awt.image.*; public class Main { /**/*ww w . ja v a 2 s. c o m*/ * Adds a two colored border to the given image. * @param src * @param outer * @param inner * @param colOuter * @param colInner * @return */ public static BufferedImage addPhotoBorder(BufferedImage src, int outer, int inner, Color colOuter, Color colInner) { BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setColor(colOuter); g2d.fillRect(0, 0, img.getWidth(), img.getHeight()); g2d.setColor(colInner); g2d.fillRect(outer, outer, img.getWidth() - 2 * outer, img.getHeight() - 2 * outer); g2d.drawImage(src, outer + inner, outer + inner, img.getWidth() - 2 * (outer + inner), img.getHeight() - 2 * (outer + inner), null); g2d.dispose(); return img; } }