Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java Newbie with Errors Question

Posted on 2011-03-06
6
Medium Priority
?
835 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 320 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 180 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
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.

 
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

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.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

636 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