Hi can one of you help me out with my final assignment in Ja
Hi can one of you help me out with my final assignment in Java? I am trying to do this blur/censor thing but I don\'t know where to start:
Here are the instructions:
public static Photograph censorIt(Photograph photo) -- This method will return a new Photograph that is meant to obscure the image and yet still be based on it.
public static Photograph censorIt(Photograph photo){
Photograph newCopy = new Photograph(getWidth, getHeight );
Thanks in advance!
Solution
/* Save the file as image.jpg The output will be blur.jpg*/
import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import javax.imageio.ImageIO;
 import java.awt.image.DataBufferByte;
 public class Blur
 {
public Blur()
 {
     try
     {
       // the line that reads the image file
       BufferedImage image = ImageIO.read(new File(\"image.jpg\"));
       int height = image.getHeight();
       int width = image.getWidth();
       int redFinal[][] = new int[width][height];
       int greenFinal[][] = new int[width][height];
       int blueFinal[][] = new int[width][height];
       System.out.println(width);
       System.out.println(height);
       for (int x=0; x<width; x+=10){
         for (int y=0; y<height; y+=10){
           int rav = 0;
           int gav = 0;
           int bav = 0;
           for(int k=0; k<10; k++){
             if(x+k<width && y+k<height){
               int clr = image.getRGB(x+k,y+k);
               int red   = (clr & 0x00ff0000) >> 16;
               int green = (clr & 0x0000ff00) >> 8;
               int blue = clr & 0x000000ff;
               rav+=red;
               gav+=green;
               bav+=blue;
             }
           }
           rav = rav/10;
           gav = gav/10;
           bav = bav/10;
for(int p=0; p<10; p++){
             if(x+p<width && y+p<height){
               redFinal[x+p][y+p] = rav;
               greenFinal[x+p][y+p] = gav;
               blueFinal[x+p][y+p] = bav;
             }
           }
         }
       }
       /* Creating image */
      int[] data = new int[width * height];
       int i=0;
       BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
       for (int x=0; x<width; x++){
         for (int y=0; y<height; y++){
           int red = redFinal[x][y];
           int green = greenFinal[x][y];
           int blue = blueFinal[x][y];
           //data[i++] = (red << 16) | (green << 8) | blue;
          int color = (red << 16) | (green << 8) | blue;
           img.setRGB(x,y,color);
         }
       }
       File f = new File(\"blur.jpg\");
       ImageIO.write(img, \"JPG\", f);
    }
     catch (IOException e)
     {
       // log the exception
       // re-throw if desired
     }
 }
public static void main(String[] args)
 {
     new Blur();
 }
}


