944,061 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 543
  • Java RSS
Nov 3rd, 2009
0

Making a Grid with a picture

Expand Post »
Alright, I posted earlier with help on compiling my method, now it compiles and now I am stuck again. Help would be great since this awful head cold is getting the best of me.

Ok so, so far I have my method almost where I need it, I have my picture that opens up in to a black area in the upper left hand corner. Now the tricky part, multiplying that image within these parameters. So if I do makeGrid(2) I should see 4 of the same picture in a grid like manner. Here is my code again:

Java Syntax (Toggle Plain Text)
  1. public Picture makeGrid(int size)
  2. {
  3. Picture targetPicture = new Picture(this.getWidth()*size, this.getHeight()*size);
  4. Pixel sourcePixel = null;
  5. Pixel targetPixel = null;
  6. int targetX = 0;
  7. int targetY = 0;
  8.  
  9. //loop through the source picture columns
  10. for(int sourceX = 0; sourceX < this.getWidth(); sourceX++)
  11. {
  12. //loop through the source picture rows
  13. for(int sourceY = 0; sourceY < this.getHeight(); sourceY++)
  14. {
  15. // get the source pixel
  16. sourcePixel = this.getPixel(sourceX,sourceY);
  17.  
  18. // loop copying to the target y
  19. for(int indexY = 0; indexY <size; indexY++)
  20. {
  21. // loop copying to the target x
  22. for(int indexX = 0; indexX < size; indexX++)
  23. {
  24. targetX = sourceX * size + indexX;
  25. targetY = sourceY * size + indexY;
  26. targetPixel =targetPicture.getPixel(targetX, targetY);
  27. targetPixel.setColor(sourcePixel.getColor());
  28. }
  29. }
  30. }
  31. }
  32. return targetPicture;
  33. }
  34. }

Any helpful hints or suggestions would be much appreciated! Thanks =D
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ah124131 is offline Offline
3 posts
since Nov 2009

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: Put ArrayList in HashMap
Next Thread in Java Forum Timeline: Regarding Coverting multiple images to a single pdf in an applet





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


Follow us on Twitter


© 2011 DaniWeb® LLC