Sabtu, 13 Desember 2014

Image Negative Using Java

Dalam pengolahan citra digital, proses pengolahan citra dapat dilakukan dengan menggunakan java. Berikut ini adalah source code java untuk membuat Image Negative dengan menggunakan java.

import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;


public class ImageNegative{
    public static void main(String args[])throws IOException{
    File file= new File("image.jpg");
    BufferedImage image = ImageIO.read(file);
    
    int w = image.getWidth();
    int h = image.getHeight();
   
    for(int y= 0; y < h; y++){
            for(int x = 0; x < w; x++){
                int pixel = image.getRGB(x,y);
                
                int a = (pixel>>24)&0xff;
                int oldR = (pixel>>16)&0xff;
                int oldG = (pixel>>8)&0xff;
                int oldB = pixel&0xff;
                
                int r = 255 - oldR;
                int g = 255 - oldG;
                int b = 255 - oldB;
                
                pixel = (a<<24) | (r<<16) | (g<<8) | b;
                image.setRGB(x, y, pixel);
            }
        }
   File ouptut = new File("output.jpg");
   ImageIO.write(image, "jpg", ouptut);
  
   }
}


Contoh Hasil Image Negative:


Written by: Admin ngampus mulu, ga mampus Updated at : 16:05

0 komentar:

Posting Komentar