I have just started learning Java; so I don't know much and could really
use some help on this since I have spent hours and I'm not getting
anywhere. I had H.W. that wanted me to do a rotate filter on an image.
I thought it would be a switch of x,y. Well, the code compiles but I'm getting all
these errors when I try to apply it. What do all these errors mean?
Here's the code:
import java.awt.Color;
public class RotateFilter extends Filter
{
public RotateFilter(String name)
{
super(name);
}
public void apply(OFImage image)
{
int height = image.getHeight();
int width = image.getWidth();
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
image.setPixel(y, x, image.getPixel(y, height-1-x));
}}}}
Here's part of the errors: They go on and on
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:301)
at java.awt.image.BufferedImage.getRGB(BufferedImage.java:871)
at OFImage.getPixel(OFImage.java:54)
at RotateFilter.apply(RotateFilter.java:33)
at ImageViewer.applyFilter(ImageViewer.java:126)
at ImageViewer.access$600(ImageViewer.java:22)
you need to create a new image to copy the rotated pixels into (as the rotated image will not be the same size as the original image), similiar to what is done when resizing an image
NewbieITGal
ASKER
Thank you to all of you for getting me back on track
with the extend Image Filter.
can you post get pixel code