Solved

Java Newbie with Errors Question

Posted on 2011-03-06
6
830 Views
Last Modified: 2012-05-11
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
Comment
Question by:NewbieITGal
6 Comments
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35046936
> >>>>>>Here the problem height-1-x


can you post get pixel code
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
ID: 35047129
I think they probably mean you to extend ImageFilter. Here's an example:

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

Assisted Solution

by:for_yan
for_yan earned 45 total points
ID: 35047170

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 92

Expert Comment

by:objects
ID: 35048276
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
 

Author Closing Comment

by:NewbieITGal
ID: 35058734
Thank you to all of you for getting me back on track
with the extend Image Filter.

Thanks again for the help.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35059721
:)
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to add new optional parameter to JSP 1 49
arguments to jar 5 35
jmss example java 2 23
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 30
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question