Hi i have been trying to write a code that takes a picture and gets the odd valued pixels and turns them red, and also get the even values pixels and make them brighter. I am stuck and any help would be appriciated.

/**
 * Decrypt.java
 * Starter file for secret image Comp 110 project
 * Ian Jones
 */

import java.awt.Image;
import java.awt.*;
import java.awt.event.*;
import javax.imageio.*;
import java.awt.image.BufferedImage;


public class Decrypt {
   String path, pictureFile;
   Picture aPicture;
   Pixel aModified;
   Pixel aBrightened;
   
   
   
   public Decrypt() {
      
      path = System.getProperty("user.dir");
      FileChooser.setMediaPath("c:/Documents and Settings/Biff/Desktop/");
      System.out.println("Get the picture to decrypt");
      pictureFile = FileChooser.pickAFile();
      aPicture = new Picture(pictureFile);
      System.out.println(aPicture);
      aPicture.show();
      
   }
   
   public void decryptPicture() {
     Pixel[] pixel;
     aPicture.explore();
       for(int x=0; x<aPicture.getWidth()-1; x++){
       for(int y=0; y<aPicture.getHeight()-1; y++){
         if((x+y)%2==0) 
           pixel.setRed(255);
           pixel.setBlue(0);
           pixel.setGreen(0);
       }
     }
     
   System.out.println("modified " + aModified + " brightened " + aBrightened 
        + " pixels");
      aPicture.repaint();
      aPicture.write("decryptedPicture.png");
      System.out.println("wrote decryptedPicture.png");
      
   }
   
   public static void main(String[] args) {
      Decrypt app = new Decrypt();
      app.decryptPicture();
      System.out.println("Decrypt is done");
   }
}

Recommended Answers

All 2 Replies

What exactly are you stuck on? Make sure to put your code in

tags...

You make use of certain classes that aren't part of the standard Java API so I'm unable to really follow the code you've given. I did notice that you create a Pixel array in method decryptPicture() and then you begin to populate the array depending on a Boolean evaluation. Since Pixel is a class you will definitely get a null exception when you attempt to populate the array.

When creating an array of objects you must instantiate each element of that array before using it. If you don't understand this concept please feel free to ask for a better explanation.

For us to better help you I need to know if you've found a way to access each pixel from the image? I notice you have classes created that seem to do this but it's safer to ask then to assume you do.

If you've successfully managed to get access to each pixel then it seems the code you're missing would be to increase the brightness of the even valued pixels; am I correct? The general way this would be done is with a filter (I think that a Gaussian filter would increase the brightness) but perhaps you could simply increase the RGB values of the pixel by some constant?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.