View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

General copy method

 /**
   * Method to copy from the passed source picture to current picture object
   * The copying will start at startX, startY, and end at endX-1 and endY-1
   * The copy will be placed starting at targetStartX, targetStartY
   * @param sourcePicture the source picture to copy from
   * @param startX the starting x value in the source picture
   * @param startY the starting y value in the source picture
   * @param endX the ending x value in the source picture
   * @param endY the ending y value in the source picture
   * @param targetStartX the starting x value in the current picture
   * @param targetStartY the starting y value in the current picture
   */
  public void copy(Picture sourcePicture, int startX, int startY, 
                   int endX, int endY, int targetStartX, int targetStartY)
  {
    Pixel sourcePixel = null;
    Pixel targetPixel = null;
    
    // loop through the x values
    for (int x = startX, tx = 0; 
         x < endX; 
         x++, tx++)
    {
      // loop through the y values
      for (int y = startY, ty = 0; 
           y < endY; 
           y++, ty++)
      {
        sourcePixel = sourcePicture.getPixel(x,y);
        targetPixel = this.getPixel(targetStartX + tx,
                                    targetStartY + ty);
        targetPixel.setColor(sourcePixel.getColor());
      }
    }
  }


Link to this Page