Cant convert .png to .tiff in intellij IDE using jmagick - java

So I'm trying to write a simple program that will change the type of an image from a .png to a .tiff using jmagick in java. I followed a tutorial that i found online for different image formats located Here. The program compiles successfully but when I run it I get this message:
Process finished with exit code -1073740940 (0xC0000374)
This is my code:
System.out.println("I'm at 0");
String inputfileName = "C:\\Users\\MySelf\\IdeaProjects\\tess4jTest\\p1.png"; //Input PNG file
ImageInfo info = new ImageInfo(inputfileName); //Get PNG file into ImageInfo object
MagickImage magick_converter = new MagickImage(info); //Create MagickImage object
System.out.println("I'm at 1")
String outputfile = "C:\\Users\\emctiern\\IdeaProjects\\tess4jTest\\p01.tiff"; //Output File name
magick_converter.setFileName(outputfile); //set output file format
magick_converter.writeImage(info); //do the conversion
System.out.println("I'm at 2");
My code never actually reaches the print 1 and 2, I think it might be that its not sure where to get the file from, That's why I entered the the full file path. In the tutorial I followed they just had the image name and nothing else.
Thanks in advance

Related

JavaFX: ImageView cannot load image that was created by the program itself. Error: java.lang.IllegalArgumentException:

I am attempting to create a program in which the user selects an image from a different folder on their computer and JavaFX copies that image into the project directory for future use. A new folder is created that will store the newly created image file. This is essentially the code for selecting and copying the image into the project directory:
Stage window = (Stage) ap.getScene().getWindow();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Select Image File");
File selectedFile = fileChooser.showOpenDialog(window);
//Creates a new directory for the new calendar that the user wants to create
File file = new File("src/DefaultUser/" + nameField.getText() + "/");
file.mkdir();
//Creates a new file name with logo as the name, but keeping the extension the same
int index = selectedFile.getName().lastIndexOf(".");
String ext = selectedFile.getName().substring(index);
//Stored in newFileName
String newFileName = "logo" + ext;
File newFile = new File(file.getPath() + "/" + newFileName);
//Copies the selected file into the project src folder, with newFileName as the new file name
Files.copy(selectedFile.toPath(), newFile.toPath());
Then the program moves onto a different scene and thus a different controller actually loads the image into an ImageView. I know that the path for the Image works properly but for whatever reason the program cannot find the image file to load it into the ImageView.
Here is essentially the code used for that:
image.setImage(new Image("DefaultUser/" + imagePath));
Don't worry about what imagePath is in this case because I am absolutely positive it paths to the correct location for the newly created image file. This is because if I close the JavaFX program and rerun it, the image loads properly.
At first, I thought it was because it took time for the image to be copied into the project directory but I checked that the file actually existed within the code and it did so this is apparently not the case. I tried using Thread.sleep() to delay the program a bit so that the code would potentially have more time to copy the file but it still threw the same error: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
The strangest part about this is that the program works perfectly fine, it's just that I have to restart the JavaFX program for it to be able to detect the image file, even though I know it exists. Is there something weird about JavaFX and creating new files and accessing them within the same program? I am truly lost. Thank you so much in advance for any help and I'm sorry if this doesn't give enough information because I don't want to have to explain the whole project.
Just like haraldK and James_D said in the comments putting stuff in the src folder is generally a bad idea. I solved the issue by moving the folder out into the project directory instead.

(Processing) Converting type file into type string?

I'm trying to get my application to open an audio file via a button (which works) and display the data of the file in the console (which also works)
The application is unable to play the file because the function needs a type String and the audio file I'm using is of type File. How do you convert a File into a String in Processing?
void setup() {
selectFile();
size(300, 300);
}
void selectFile() {
selectInput("Select a file to process:", "fileSelected");
}
void songTag(File selection) {
File file = new File(selection.getPath());
song = minim.loadFile(filepath);
song.play();
}
}
}
Check out the Java API to understand Java classes and functions.
The File class has several useful functions. You probably want the getAbsolutePath() function.
I'm not sure which line of code is showing the compiler error, but you might try something like this:
Mp3File mp3file = new Mp3File(selection.getAbsolutePath());
song = minim.loadFile(selection.getAsbolutePath());
Also note that the code you posted has other errors: the filepath function is never defined, for example. In the future, please try to post a MCVE that actually shows exactly what you're trying to do.

How to add the album art to a .mp3 file using mp3agic?

I have been trying to set the album art of a mp3 file using the mp3agic library in java. The following code snippet is what i used to do so. Unfortunately this isnt working. The saved image file does not contain the album art nor the set title. Also, the program compiles with no error.
File img = new File("img.jpg");
imgLink[1]="http://"+imgLink[1];
URL url = new URL(imgLink[1]);
FileUtils.copyURLToFile(url, img);
byte[] bytes = new byte[(int) img.length()];
id3v2Tag.setTitle("Something");
id3v2Tag.setAlbumImage(bytes, "image/jpg");
mp3file.save("something.mp3");
Any help regarding this issue would be much appreciated.
The above code works. It wasn't showing properly on the folder I was working with. When I opened the file with iTunes it showed up. It's probably some fault with windows.

Is it possible to use Sikuli to assert that images are the same in GUI-less mode?

I have a testing server which runs headless. One test I want is to check that an image served off a particular URL matches some reference image.
Is there an API in Sikuli which can directly accept an image as a stream and compare it with some other image taken from the local resource file? Unfortunately, there is no complete tutorial on Sikuli's Java API, all I've found is tutorials that assume that there is a display available.
I'll be glad to see any examples or at least links to the needed parts of Sikuli javadocs. Also, suggestions for other approaches are welcome.
To use Sikuli you need
A base image on which the other image will be searched.
The image which will be searched within the other image.
If image 1 is your local resource image, you can create a org.sikuli.Finder instance with the path to the image and the Region of this image which will be searched.
Example (java level):
finder = new Finder("path/to/image", new Region(0, 0, <imgwidth>, <imgheight>));
If image 1 is your stream, you have to make a BufferedImage out of it somehow (I do not know the best way to do this).
Then you can make a org.sikuli.ScreenImage from this BufferedImage with the help of an java.awt.Rectangle and an org.sikuli.Region.
finder = new Finder(new ScreenImage(new Rectangle(0,0,<imgwidth>,<imgheight>), bufferedImage), new Region(0,0,<imgwidth>,<imgheight>))
After you created the finder from image 1, you can search image 2 within this image.
Again, you have two possibilities.
If the second image is your local resource image, you can create an org.sikuli.Pattern object with the file location:
pattern = new Pattern("path/to/image.png");
Else, if this is your stream, you have to make a BufferedImage out of the stream somehow. You can then create a pattern from this image:
pattern = new Pattnern(bufferedImage);
As a last step, you can now run the finder to search for the pattern:
finder.find(pattern);
You can check if the finder found anything with:
finder.hasNext();
And you should be able to iterate all findings with:
for (Match m : finder):
//do something with the match
I hope I could help you although your question is already some weeks old.
Below code helps for asserting images
//take screenshots
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
//copy it some location
FileUtils.copyFile(scrFile, new File("C:\\screenshot.png"));
Finder f = new Finder("C:\\screenshot.png");
System.out.println("abc");
f.find("C:\\chrome3.png", 0.95);
while(f.hasNext()){
System.out.println("found");
Match m= f.next();
f.destroy();
}
}
catch (IOException e)
{
e.printStackTrace();
}

How to read big bufferedimage

I am reading a 100 MB picture into my app. It works fine inside Eclipse, but not when I export project to a JAR. Then, I get "Can't read input file!"
Since I need to edit it, I used BufferedImage.
private String str = "images/1.png";
BufferedImage imageMap;
//in constructor
imageMap = ImageIO.read(new File(str));
I have tried this, but the project image does not load inside Eclipse:
imageMap = ImageIO.read(this.getClass().getClassLoader().getResource(str));
Check you working directory if the image is loaded from the file system. Then you see if your relative path "images/1.png" is valid. Or you directly check the path of your png
System.out.println(new File("."));
File f = new File("images/1.png");
System.out.println(f.getAbsolutePath());

Categories

Resources