• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 840
  • Last Modified:

Java Newbie with Errors Question

Hi All,

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)

Thanks in advance for any help.
      
0
NewbieITGal
Asked:
NewbieITGal
2 Solutions
 
Sathish David Kumar NCommented:
> >>>>>>Here the problem height-1-x


can you post get pixel code
0
 
CEHJCommented:
I think they probably mean you to extend ImageFilter. Here's an example:

http://www.enme.umd.edu/ESCML/Courseware/Rotate90DegreeFilter.java
0
 
for_yanCommented:

Has your image square shape  - so that always width == height ?
If not then
as the first position corresponds to width, and your y corresponds to height,
so if your image is rectangular (not square) , then y in the fist position going up to height
will become higher than the limit of your image on the width if height > width, or
there wiil be similar problem on the second position if height < width.

I am also not sure you can manipulate all within one image - it is safer to create new image instance
with the same dimensions and assign pixels of image1 to image
and then replace the whole image.

Of course to extend ImageFilter as CEHJ suggested is probably the way the do such things

 
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
objectsCommented:
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
0
 
NewbieITGalAuthor Commented:
Thank you to all of you for getting me back on track
with the extend Image Filter.

Thanks again for the help.
0
 
CEHJCommented:
:)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now