Created
October 10, 2017 10:57
-
-
Save AliZafar120/df05fc7a9b3cfde9f951bb18434b607e to your computer and use it in GitHub Desktop.
converting image into negative image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.image.BufferedImage; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStreamWriter; | |
import java.io.RandomAccessFile; | |
import java.io.Writer; | |
import java.nio.channels.FileChannel; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.stream.Stream; | |
import javax.imageio.ImageIO; | |
public class TransformFiles { | |
public static void main(String[] args) throws IOException { | |
final File folder= new File("C:\\Users\\User\\Desktop\\Road and Cars\\Road_negatives"); | |
for (final File fileEntry : folder.listFiles()) { | |
BufferedImage inputFile = null; | |
try { | |
inputFile = ImageIO.read(fileEntry); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
for (int x = 0; x < inputFile.getWidth(); x++) { | |
for (int y = 0; y < inputFile.getHeight(); y++) { | |
int rgba = inputFile.getRGB(x, y); | |
Color col = new Color(rgba, true); | |
col = new Color(255 - col.getRed(), | |
255 - col.getGreen(), | |
255 - col.getBlue()); | |
inputFile.setRGB(x, y, col.getRGB()); | |
} | |
} | |
try { | |
File outputFile = new File("C:\\Users\\User\\Desktop\\Road and Cars\\negative\\"+fileEntry.getName()); | |
ImageIO.write(inputFile, "jpg", outputFile); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
/* | |
* | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment