Solved

Linux Java: Green Screen Effect

Posted on 2013-01-28
11
490 Views
Last Modified: 2013-02-04
Hello experts,

I am relatively new to the Java Programming language and am completely new in the Linux OS. I am currently trying to create a program that is capable of taking an image and replacing a "green screen" with a second image much like how new channels do the weather reports. Unfortunately, I do not quite understand many of the classes that I may need to use such as the File class and was hoping that you can either explain them or refer me to some sites where I can better understand them.

Thank you for your time.
0
Comment
Question by:Paul_ATL
[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
  • 4
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 38829203
Please explain the functionality that you need, without even mentioning Java classes. Don't try to anticipate what classes you need. Just say what you want it to do
http://technojeeves.com/joomla/index.php/free/117-smart-questions
0
 
LVL 36

Expert Comment

by:mccarl
ID: 38830728
Agree with what CEHJ has said above, but I would also add; a good place to start is the Java Tutorials
0
 

Author Comment

by:Paul_ATL
ID: 38831471
The functionality that I need is for the program to be able to identify two image files of the same dimensions specified by a user and transpose one of them onto the other in place of a solid "green screen" color. Once that's done, it needs to be able allow the user to save the new image.

Edit: I have attached the code that I have done so far along with an image of what errors came up while I was trying to compile. The compilation errors are from me testing to see that the code I have written so far works. For now, I am not certain how to change the code to read files specified by the user. I only know how to get the program to load up a specific file based on the filename. During the compilation, I used specific filenames, but have deleted them from the code that I have uploaded.
GreenScreen.java
ErrorMessages.jpg
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 38832036
public LoadForeImage()

Open in new window

would be a constructor, which is not what you intend. What you need is

public void loadForeImage()

Open in new window

(method names in Java begin lower case)
0
 

Author Comment

by:Paul_ATL
ID: 38832113
I decided to change my code and moved the image reading process into the main method. After doing this, the program was able to compile with the new code, but I do not know how to set it up read the images. I will attach the new code here as well.

Thank you for your help.
GreenScreen.java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38832539
It's a start. It's not far off, though there seems to be a little confusion and some duplication and strange file names.

a. you need to use proper methods in your class - there should be very little code in main
b. it's preferable (assuming your images are read-only) to load them as resources

http://technojeeves.com/joomla/index.php/free/126-loading-files-as-resources-in-java-with-netbeans
http://technojeeves.com/joomla/index.php/free/120-loading-files-as-resources-in-java-with-eclipse
e.g.
foreImage = ImageIO.read(getClass().getResourceAsStream("/images/foreImg.png"));

Open in new window

0
 

Author Comment

by:Paul_ATL
ID: 38833630
I have added in the code that should (hopefully) check to ensure that the files both exist and are readable. I have also moved the BufferedImage class coding portions back into the main method after the checking portion. Right now, the program gets an error about the getClass() being a non-static method being unusable as a reference from a static context. In order to get around that, I have removed that code for now.

The only error I am getting so far now has to deal with creating the file objects at the beginning of the main method. I am trying to get it so that the user specifies the file they want as args[0]. Because this is creating an error, I am assuming there will also be an error for the second file object that will become args[1].

I am attaching the new code that I have written so far. Thank you for your help.
GreenScreen.java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38834863
being a non-static method being unusable as a reference from a static context. In order to get around that, I have removed that code for now.
As i already said above, that code should not be in main. That's the reason for your problem. Move it out into a non-static method
0
 

Author Comment

by:Paul_ATL
ID: 38836230
I have moved the file check and the buffer codes to a separate class and re-implemented the the getClass() method as well. This is so that I can have the large portion of code in a separate helper function that the main program can call upon. I have tried compiling the new code to make sure that it can be compiled and have gotten several errors, some for illegal start of expression as well as some others that I do not quite understand.
GreenScreen.java
ImageFile.java
ErrorMessages3.jpg
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38836851
Your errors show me that you're starting to try to run before you can walk. You need to get the basics down on classes and methods. Take the Oracle tutorials
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38850276
:)
0

Featured Post

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.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:

691 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