Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Colour invert - Java Code Bank


Colour invert
This will colour invert a given image
                /**
*@Auther  :Tharindra Galahena
*@Project :Colour invert
*@Date    :21/01/2011  
*/


import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.imageio.ImageIO;

public class Colour_inv{
	public static void main(String args[]){
	
		if(args.length < 2){
			System.out.println("USAGE: \n\n \t Colour_inv [input file] [output file] \n\n" +
							   "ex: \n" +
							   "\t im in.jpg out.jpg");	
			System.exit(0);
				
		}						   
		try {
				
				BufferedImage img = ImageIO.read(new File(args[0]));
				Raster raster = img.getData();
				int height = raster.getHeight();
				int width = raster.getWidth();
				int size = height*width;
				int [] pixels = new int[size * 3];
				raster.getPixels(0, 0, width, height, pixels);
 
				
				int k = 0;
				for(int i = 0; i < width*height*3; i++){
					pixels[k] = 255 - pixels[k];
					k ++;
				}
				BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
				WritableRaster raster2 = (WritableRaster) image.getData();
				raster2.setPixels(0,0,width,height,pixels);
				image.setData(raster2);
			
				File outputfile = new File(args[1]);
				ImageIO.write(image, "jpg", outputfile);

			}catch(Exception e){
				System.out.println(e);
			}
	}
}
            
Comments
Sorry but there are no comments to display