Making a Grid with a picture

Reply

Join Date: Nov 2009
Posts: 3
Reputation: ah124131 is an unknown quantity at this point 
Solved Threads: 0
ah124131 ah124131 is offline Offline
Newbie Poster

Making a Grid with a picture

 
0
  #1
24 Days Ago
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:

  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
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC