Java Reference
In-Depth Information
public final BufferedImage filter (BufferedImage source
-
img,
BufferedImage dest
-
img)
{
// If no destination image provided, make one of same
// form as source
if (dest
-
img == null)
dest
-
img = createCompatibleDestImage
(source
-
img, null);
int width
=
source
-
img.getWidth ();
int height
=
source
-
img.getHeight ();
for (int y
=
0; y
<
height; y++)
{
for (int x
=
0; x
<
width; x++)
{
int pixel = source
-
img.getRGB (x,y);
// Get the component colors
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = pixel
& 0xff;
// Rotate the values
int tmp
=
blue;
blue
=
green;
green
=
red;
red
=
tmp;
// Put new value into corresponding pixel of
// destination image;
pixel
=
(255
<<
24)
|
(red
<<
16)
|
(green
<<
8)
|
blue;
dest
-
img.setRGB (x,y,pixel);
}
}
return dest
-
img;
}
// filter
/**
*Create a destination image if needed. Must be same
*width as source and will by default use the same
*color model. Otherwise, it will use the one passed
*toit.
*/
public BufferedImage createCompatibleDestImage (
BufferedImage source
-
img,
ColorModel dest
-
color
-
model
)
{
Search WWH ::
Custom Search