This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Not calling displayImage() method?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Why this line ?
 
Kar Man
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
please post convertToGreyScale code
 
Kar Man
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:please post convertToGreyScale code


Here is my code for that method:
 
Marshal
Posts: 65005
246
  • Mark post as helpful
  • send pies
  • 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: 3406
149
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!