1 7 package org.jboss.media.exampleplugins; 8 9 import java.awt.Color ; 10 import java.awt.Rectangle ; 11 import java.awt.image.BufferedImage ; 12 13 import org.jboss.media.engine.image.ImagePluginSupport; 14 15 19 public class AddImageBordersPlugin extends ImagePluginSupport 20 { 21 22 25 public void processImage(BufferedImage image) 26 { 27 28 Rectangle [] rec = new Rectangle [3]; 29 rec[0] = new Rectangle (0, 0, image.getWidth()-1, image.getHeight()-1); 30 rec[1] = new Rectangle (1, 1, image.getWidth()-2, image.getHeight()-2); 31 rec[2] = new Rectangle (2, 2, image.getWidth()-3, image.getHeight()-3); 32 drawRectangles(rec,image); 33 } 34 35 private BufferedImage drawRectangles(Rectangle [] rec, BufferedImage img) 36 { 37 for (int i = 0; i < rec.length; i++) 38 { 39 img = 40 drawRectangle( 41 (int) rec[i].getX(), 42 (int) rec[i].getY(), 43 (int) rec[i].getWidth(), 44 (int) rec[i].getHeight(), 45 img); 46 } 47 48 return img; 49 } 50 51 private BufferedImage drawRectangle( 52 int x0, 53 int y0, 54 int x1, 55 int y1, 56 BufferedImage img) 57 { 58 59 if (y1 > img.getHeight() || x1 > img.getWidth()) 60 return img; 61 if (y0 > img.getHeight() || x0 > img.getWidth()) 62 return img; 63 64 int temp = x0; 65 while (temp < x1 && temp < img.getWidth()) 66 { 67 img.setRGB(temp, y0, Color.green.getRGB()); 71 img.setRGB(temp, y1, Color.green.getRGB()); 72 temp++; 73 74 } 75 76 temp = y0; 77 while (temp < y1 && temp < img.getHeight()) 78 { 79 img.setRGB(x0, temp, Color.green.getRGB()); 83 img.setRGB(x1, temp, Color.green.getRGB()); 84 temp++; 85 86 } 87 88 return img; 89 } 90 91 } 92 | Popular Tags |