Hey everyone, I am still very much a beginner in programming, and i am facing an issue with a code that i am hoping someone could help me with. I found the code below for overlaying and comparing the pixels of two images in an online forum. When i try to compile the code i get a syntax error. Hope you can help me find the error. Thanks in advance.
Code: -
package stackexchange;
-
-
import java.awt.Color;
-
import java.awt.image.BufferedImage;
-
import java.io.File;
-
import java.io.IOException;
-
-
import javax.imageio.ImageIO;
-
-
public class PictureOverlayTest {
-
/*
-
* Four variables, three for the wanted BufferedImages, one String for the
-
* Path of the third Image, which does not already exist.
-
*/
-
-
private BufferedImage image1;
-
private BufferedImage image2;
-
private BufferedImage image3;
-
-
private String pathImage3;
-
-
public PictureOverlayTest(String filePathAndName1, String filePathAndName2,
-
String filePathAndName3) throws IOException {
-
/*
-
* Constructor in order to keep this method reusable and clean. Needs
-
* three Strings. The paths and Filenames of all three images. Image 1
-
* and 2 should exist already, Image 3 will be created if all
-
* requirements are met. Constructor creates the first two buffered
-
* images, sets all needed variables and starts the checkAndCompare()
-
* method
-
*/
-
-
File file = new File(filePathAndName1);
-
this.image1 = ImageIO.read(file);
-
-
file = new File(filePathAndName2);
-
this.image2 = ImageIO.read(file);
-
-
this.pathImage3 = filePathAndName3;
-
checkAndCompare();
-
}
-
-
private void checkAndCompare() throws IOException {
-
/*
-
* This function creates the Color blue, compares the sizes of both
-
* pictures and if they are the same, creates a third image. Then it
-
* loops through the two images and compares each pixel. If the pixels
-
* are the same, the third image gets a blue pixel at that point
-
*/
-
-
Color blue = Color.blue;
-
-
if (image1.getHeight() == image2.getHeight()
-
&& image1.getWidth() == image2.getWidth()) {
-
-
image3 = new BufferedImage(image1.getWidth(), image1.getHeight(),
-
image1.getType());
-
for (int y = 0; y < image1.getHeight(); y++) {
-
for (int x = 0; x < image1.getWidth(); x++) {
-
-
int colorImage1 = image1.getRGB(x, y);
-
int colorImage2 = image2.getRGB(x, y);
-
-
if (colorImage1 == colorImage2) {
-
-
image3.setRGB(x, y, blue.getRGB());
-
-
} else {
-
-
// Whatever Color you want. By default it is black.
-
-
}
-
-
}
-
}
-
savePicture3();
-
System.out.println("Message: Image comparison is done");
-
-
} else {
-
-
System.out.println("Error: Image dimensions do not match");
-
-
}
-
-
}
-
-
private void savePicture3() throws IOException {
-
/*
-
* This method saves the created Image into a file onto your computer.
-
* The if() statement is used to check if the file was successfully
-
* created, in order to avoid unwanted errors. Keep in mind, that you
-
* have to change the "bmp" in ImageIO.write() to whatever format you
-
* actually want
-
*/
-
-
File file = new File(pathImage3);
-
if (file.createNewFile()) {
-
ImageIO.write(image3, "bmp", file);
-
}
-
}
-
-
}
-
-
package stackexchange;
-
-
import java.io.IOException;
-
-
public class Main {
-
-
public static void main(String[] args) {
-
// TODO Auto-generated method stub
-
-
try {
-
PictureOverlayTest test = new PictureOverlayTest(
-
"H:\\stackexchange\\file1.bmp",
-
"H:\\stackexchange\\file2.bmp",
-
"H:\\stackexchange\\file3.bmp");
-
} catch (IOException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
}
-
}
-
-
}
-
4 4187
Hey everyone, I am still very much a beginner in programming, and i am facing an issue with a code that i am hoping someone could help me with. I found the code below for overlaying and comparing the pixels of two images in an online forum. When i try to compile the code i get a syntax error.
What error?
Three code errors am getting are:
When trying to rung the code i get a window saying "The selection cannot be launched, and there are no recent launches"
next to the first code line "module Image_Overlay {" am getting the error "Syntax error on token(s), misplaced construct(s)"
next to code line Nr. 7 am getting the error "The type java.awt.image.BufferedImage is not accessible"
and some others, but i think these are the main ones.
The code doesnt compile at all it just says syntax error
I can compile the code posted in #1 fine (no package, same directory)
"module Image_Overlay {" am getting the error "Syntax error on token(s), misplaced construct(s)"
The code posted in #1 contains no such line.
When trying to rung the code i get a window saying "The selection cannot be launched, and there are no recent launches"
The dialogs could be specific to the IDE you're using. You may need to refer to its manual.
"The type java.awt.image.BufferedImage is not accessible"
My guess is with an IDE, one needs to configure/add/mention the required packages manually under the project settings before using them.
and some others, but i think these are the main ones.
Subsequent errors could show up because of one root error.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PW |
last post by:
I'm trying to interrogate an incoming value from a previous ASP like this
....
myCurrentQty = request.querystring("txtBCQty" & myRecordCounter)
It returns a "2" as expected.
But if I try to...
|
by: Robert Peden |
last post by:
Hi All,
I have used javascript to chamge a button's image when the mouse moves
over the button (graphic) without problems. But I have come upon a new
challenge - buttons which overlay each...
|
by: John |
last post by:
Hi
I am getting the 'Operator is not valid for type 'DBNull' and string "".'
error on the following line;
If (mydatatable.Rows.Item(I).Item("Forenames") Is System.DBNull.Value) Then
' 'I' is...
|
by: SonyMan |
last post by:
HI
I have a VB.NET application in which my Image (from a picturebox) is opened by the user in another application like MSPaint or Photoshop or whatever he chooses. The image does open there.But...
|
by: bjjnova |
last post by:
I have the following string comparison that is throwing an error I
cannot find ( I will include my attempts to trace the error)
In the line following the asterisks, written as I have below, a...
|
by: labby |
last post by:
I've application to capture video of image and grab the still image. It runs well untill I put loop to regrab the still images many times automatically.. and the error (generic error occured GDI+)...
|
by: chazzy69 |
last post by:
Hi, im just trying to compare a character(char) to a set list of characters (e.g. "a", "b", etc).
first i read in the value- (i have tried this two ways)
scanf("%c", &var_name);
//also tried...
|
by: mnflint |
last post by:
I am having a problem resizing multiple images at a time.
The images are 13200x20394 1bpp png images. In my sample set of 10 I can proess 4 before I get an "Out of memory" error. I am running...
|
by: ShruthiR |
last post by:
I am using ubuntu 10.10. In my rails 3.1 project, i am not able to upload any type of image files. While uploading an image file it shows an validation error like
/tmp/image1.jpg is not recognized...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |