If you have to convert a lot of images from one format into another the following code snippet might be of use.
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
@Test
public void testConvertImages() throws IOException {
File[] files = FileHandling.getMatchingFilePathFromDirectory(
".+\\.png", new File("C:\\Users\\xxx\\Upload\\screens\\"));
int i = 0;
for (File file : files) {
BufferedImage img = ImageIO.read(file);
ImageIO.write(img, "jpg", new File(
"C:\\Users\\xxx\\Upload\\screens\\"
+ file.getName().replace(".png", ".jpg")));
}
}
The class FileHandling is part of a little util file library I implemented and it is not needed to get this working.
-
-
-
Hits: 3596