Solved

Java Newbie with Errors Question

Posted on 2011-03-06
6
822 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
Comment Utility
> >>>>>>Here the problem height-1-x


can you post get pixel code
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
Comment Utility
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
Comment Utility

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Expert Comment

by:objects
Comment Utility
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
Comment Utility
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
Comment Utility
:)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now