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 4175
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: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |