KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > exampleplugins > AddImageBordersPlugin


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.media.exampleplugins;
8
9 import java.awt.Color JavaDoc;
10 import java.awt.Rectangle JavaDoc;
11 import java.awt.image.BufferedImage JavaDoc;
12
13 import org.jboss.media.engine.image.ImagePluginSupport;
14
15 /**
16  * @version <tt>$Revision: 1.1 $</tt>
17  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
18  */

19 public class AddImageBordersPlugin extends ImagePluginSupport
20 {
21
22    /* (non-Javadoc)
23     * @see org.jboss.media.engine.image.ImagePluginSupport#processImage(org.jboss.media.engine.image.BufferedImageHolder)
24     */

25    public void processImage(BufferedImage JavaDoc image)
26    {
27       
28       Rectangle JavaDoc[] rec = new Rectangle JavaDoc[3];
29       rec[0] = new Rectangle JavaDoc(0, 0, image.getWidth()-1, image.getHeight()-1);
30       rec[1] = new Rectangle JavaDoc(1, 1, image.getWidth()-2, image.getHeight()-2);
31       rec[2] = new Rectangle JavaDoc(2, 2, image.getWidth()-3, image.getHeight()-3);
32       drawRectangles(rec,image);
33    }
34
35    private BufferedImage JavaDoc drawRectangles(Rectangle JavaDoc[] rec, BufferedImage JavaDoc 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 JavaDoc drawRectangle(
52       int x0,
53       int y0,
54       int x1,
55       int y1,
56       BufferedImage JavaDoc 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          // System.out.println(temp);
68
// System.out.println(y0);
69
// System.out.println(y1);
70
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          //System.out.println(temp);
80
// System.out.println(x0);
81
// System.out.println(x1);
82
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