Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Not calling displayImage() method?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I am having issues with calling one of my methods, specifically displayImage(). I am supposed to use this program to convert an image from a file to grey scale, high contrast, or negative based on user input. User input is also prompted to ask the user which image they would like to convert. This is the code thus far:



My main problem is with calling the displayImage() method -- the methods that come after that can actually be ignored for now. I am using the DrawingPanel.java (https://www.buildingjavaprograms.com/DrawingPanel.java) ImageInfo.java, which is



I am not sure if you need that information to solve this question, because again, my main problem is the method not being called, and not knowing how to initialize ImageInfo image in the main method of the program. Thank you in advance for any insight on this.
 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why this line ?
 
Kar Man
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Joe wrote:Why this line ?



The calling method must catch the IllegalArgumentException thrown from the getImageList() method, display the message, and exit, so that's why I implemented this!
 
John Joe
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please post convertToGreyScale code
 
Kar Man
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Joe wrote:please post convertToGreyScale code


Here is my code for that method:
 
Marshal
Posts: 72657
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you have so many static methods in the first post? Why have you overridden equals() without overriding hashCode()?
How do you know the method isn't called? Have you put any debugging code in it? Why does that method have a drawing panel local variable?
How are you implementing keyboard input? Is there any chance of your calling nextLine() after nextInt() or similar?
Why have you got an infinite loop in lines 61ff. Why are you closing a Scanner reading from System.in?
Why are you catching unchecked exceptions? Are you suffering any exceptions at all?
There are all sorts of other minor problems, but what actually happens when you try to run your code?
 
Saloon Keeper
Posts: 4380
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to run your program, but I get a lot of errors, so that did not work.

First of all: have a look a line 103. That should not cause the displayImage() not being called, but it is incorrect anyway.

Can't you put a 'System.out.println("I'm in displayImage") at the start of that method? Then it is clear right away whether that method is called or not. If not, add that statement at some more places, to see where your program gets, and where potentially an error occurs.

Java has some classes that will do image maniputation for you, without you having to perform much pixel juggling. See the interface BufferedImageOp and its implementing classes. There is also some tutorial from Oracle:

BuffreredImageOp tutorial

And, usually when converting from color to greyscale, the weights of red, green and blue are often 2 : 4 : 1.

You can make irt yorself easy by, for instance, defining a BufferedImage.Type_Byte_Gray, and draw your color image in it, letting Java do all the hard work.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic