943,703 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 516
  • Java RSS
Nov 4th, 2008
0

Help with a drycrpt program

Expand Post »
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.

Java Syntax (Toggle Plain Text)
  1. /**
  2.  * Decrypt.java
  3.  * Starter file for secret image Comp 110 project
  4.  * Ian Jones
  5.  */
  6.  
  7. import java.awt.Image;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.imageio.*;
  11. import java.awt.image.BufferedImage;
  12.  
  13.  
  14. public class Decrypt {
  15. String path, pictureFile;
  16. Picture aPicture;
  17. Pixel aModified;
  18. Pixel aBrightened;
  19.  
  20.  
  21.  
  22. public Decrypt() {
  23.  
  24. path = System.getProperty("user.dir");
  25. FileChooser.setMediaPath("c:/Documents and Settings/Biff/Desktop/");
  26. System.out.println("Get the picture to decrypt");
  27. pictureFile = FileChooser.pickAFile();
  28. aPicture = new Picture(pictureFile);
  29. System.out.println(aPicture);
  30. aPicture.show();
  31.  
  32. }
  33.  
  34. public void decryptPicture() {
  35. Pixel[] pixel;
  36. aPicture.explore();
  37. for(int x=0; x<aPicture.getWidth()-1; x++){
  38. for(int y=0; y<aPicture.getHeight()-1; y++){
  39. if((x+y)%2==0)
  40. pixel.setRed(255);
  41. pixel.setBlue(0);
  42. pixel.setGreen(0);
  43. }
  44. }
  45.  
  46. System.out.println("modified " + aModified + " brightened " + aBrightened
  47. + " pixels");
  48. aPicture.repaint();
  49. aPicture.write("decryptedPicture.png");
  50. System.out.println("wrote decryptedPicture.png");
  51.  
  52. }
  53.  
  54. public static void main(String[] args) {
  55. Decrypt app = new Decrypt();
  56. app.decryptPicture();
  57. System.out.println("Decrypt is done");
  58. }
  59. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thebiff is offline Offline
10 posts
since Nov 2008
Nov 4th, 2008
0

Re: Help with a drycrpt program

What exactly are you stuck on? Make sure to put your code in tags...
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008
Nov 5th, 2008
0

Re: Help with a drycrpt program

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?
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: hi! can anyone please help me complete this code
Next Thread in Java Forum Timeline: create database at run time





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC