/** * 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()); } } }
public boolean compareImages(Image image1, Image image2, Rectangle rect, String attach) { if (image1 == null || image2 == null) return false; boolean matched = false; Iterator iter1 = handlePixels(image1, rect); Iterator iter2 = handlePixels(image2, rect); while (iter1.hasNext() && iter2.hasNext()) { Pixel pixel = (Pixel) iter1.next(); if (pixel.equals((Pixel) iter2.next())) { matched = true; } else { matched = false; } } if (matched) return true; return false; }