Solved

Java Newbie with Errors Question

Posted on 2011-03-06
6
832 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 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
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.

705 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