Ejemplo n.º 1
0
 /**
  * A Constructor that takes a picture to copy information from
  *
  * @param copyPicture the picture to copy from
  */
 public SimplePicture(SimplePicture copyPicture) {
   if (copyPicture.fileName != null) {
     this.fileName = new String(copyPicture.fileName);
     this.extension = copyPicture.extension;
   }
   if (copyPicture.title != null) this.title = new String(copyPicture.title);
   if (copyPicture.bufferedImage != null) {
     this.bufferedImage =
         new BufferedImage(
             copyPicture.getWidth(), copyPicture.getHeight(), BufferedImage.TYPE_INT_RGB);
     this.copyPicture(copyPicture);
   }
 }
Ejemplo n.º 2
0
  /**
   * Method that will copy all of the passed source picture into the current picture object
   *
   * @param sourcePicture the picture object to copy
   */
  public void copyPicture(SimplePicture sourcePicture) {
    Pixel sourcePixel = null;
    Pixel targetPixel = null;

    // loop through the columns
    for (int sourceX = 0, targetX = 0;
        sourceX < sourcePicture.getWidth() && targetX < this.getWidth();
        sourceX++, targetX++) {
      // loop through the rows
      for (int sourceY = 0, targetY = 0;
          sourceY < sourcePicture.getHeight() && targetY < this.getHeight();
          sourceY++, targetY++) {
        sourcePixel = sourcePicture.getPixel(sourceX, sourceY);
        targetPixel = this.getPixel(targetX, targetY);
        targetPixel.setColor(sourcePixel.getColor());
      }
    }
  }