public static void main(String[] args) { Picture p = new Picture(FileChooser.getMediaPath("horse.jpg")); Graphics g = p.getGraphics(); Point ul = new Point(68, 24); Point te = new Point(182, 123); String message = "This is a test." + " Of a message with more than one line in it."; SpeechBalloon balloon = new SpeechBalloon(ul, 200, te, message); balloon.draw(g); p.show(); }
/* Main method for testing - each class in Java can have a main * method */ public static void main(String[] args) { Picture beach = new Picture("beach.jpg"); beach.explore(); beach.mirrorVerticalBottomToTop(); // beach.mirrorVerticalRightToLeft(); // beach.Grayscale(); // beach.maxBlue(); // beach.createCollage(); // beach.rightRed(); beach.explore(); // beach.write("5FilterBeach.jpeg"); }
/** Method to create a collage of several pictures */ public void createCollage() { Picture flower1 = new Picture("flower1.jpg"); Picture flower2 = new Picture("flower2.jpg"); this.copy(flower1, 0, 0); this.copy(flower2, 100, 0); this.copy(flower1, 200, 0); Picture flowerNoBlue = new Picture(flower2); flowerNoBlue.zeroBlue(); this.copy(flowerNoBlue, 300, 0); this.copy(flower1, 400, 0); this.copy(flower2, 500, 0); this.mirrorVertical(); this.write("collage.jpg"); }
/* Main method for testing - each class in Java can have a main * method */ public static void main(String[] args) { Picture desert = new Picture("Desert.jpg"); Picture koala = new Picture("Koala.jpg"); // beach.explore(); // beach.zeroBlue(); // desert.chromakey(koala); // desert.sepia(25, 3); koala.sepia(); // desert.encode("ABCDEFGHIJKLMNOPasdfgwe6"); // System.out.println(desert.decode()); // desert.explore(); koala.explore(); }
public void cropAndCopy( Picture sourcePicture, int startSourceRow, int endSourceRow, int startSourceCol, int endSourceCol, int startDestRow, int startDestCol) { Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); Color rightColor = null; Pixel[][] fromPixels = sourcePicture.getPixels2D(); Pixel[][] toPixels = this.getPixels2D(); Pixel fromPixel = null; Pixel toPixel = null; for (int fromRow = startSourceRow, toRow = endSourceRow; fromRow < fromPixels.length && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = startSourceCol, toCol = endSourceCol; fromCol < fromPixels[0].length && toCol < toPixels[0].length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
/** * Method to create a new picture by scaling the current picture by the given x and y factors * * @param xFactor the amount to scale in x * @param yFactor the amount to scale in y * @return the resulting picture */ public Picture scale(double xFactor, double yFactor) { // set up the scale transform AffineTransform scaleTransform = new AffineTransform(); scaleTransform.scale(xFactor, yFactor); // create a new picture object that is the right size Picture result = new Picture((int) (getWidth() * xFactor), (int) (getHeight() * yFactor)); // get the graphics 2d object to draw on the result Graphics graphics = result.getGraphics(); Graphics2D g2 = (Graphics2D) graphics; // draw the current image onto the result image scaled g2.drawImage(this.getImage(), scaleTransform, null); return result; }
/** * Method to replace blue pixels with pixels from the second picture. * * @param second picture to replace blue pixels with */ public void chromakey(Picture second) { Pixel[][] pixels = this.getPixels2D(); Pixel[][] pixels2 = second.getPixels2D(); for (int row = 0; row < pixels.length; row++) for (int col = 0; col < pixels[0].length; col++) if (pixels[row][col].getColor().getBlue() >= 200) pixels[row][col].setColor(pixels2[row][col].getColor()); }
public static void main(String[] args) { String fileName = FileChooser.pickAFile(); Picture pictObj = new Picture(fileName); pictObj.changeWhole(.5); pictObj.changeWhole(.8); pictObj.scrible(200, 200, 50); pictObj.scrible(350, 320, 100); pictObj.ManipBoxUniformly(200, 200, 300, 300, .2); pictObj.ManipBoxUniformly(100, 100, 400, 300, .5); pictObj.ManipBoxPattern(100, 100, 300, 300, .3); pictObj.ManipBoxPattern(300, 300, 400, 400, .8); pictObj.explore(); }
/** * copy from the passed fromPic to the specified startRow and startCol in the current picture * * @param fromPic the picture to copy from * @param startRow the start row to copy to * @param startCol the start col to copy to */ public void copy(Picture fromPic, int startRow, int startCol) { Pixel fromPixel = null; Pixel toPixel = null; Pixel[][] toPixels = this.getPixels2D(); Pixel[][] fromPixels = fromPic.getPixels2D(); for (int fromRow = 0, toRow = startRow; fromRow < fromPixels.length && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = 0, toCol = startCol; fromCol < fromPixels[0].length && toCol < toPixels[0].length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
public void copy( Picture fromPic, int fromStartRow, int fromStartCol, int toStartRow, int toStartCol, int fromEndRow, int fromEndCol) { Pixel fromPixel = null; Pixel toPixel = null; Pixel[][] toPixels = this.getPixels2D(); Pixel[][] fromPixels = fromPic.getPixels2D(); for (int fromRow = fromStartRow, toRow = toStartRow; fromRow <= fromEndRow && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = fromStartCol, toCol = toStartCol; fromCol <= fromEndCol && toCol < toPixels.length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
/** Method to create a collage of several pictures */ public void createCollage() { Picture pic2 = new Picture("moon-surface.jpg"); Picture picNoBlue = new Picture(pic2); picNoBlue.zeroBlue(); Picture effect1 = new Picture(pic2); effect1.edgeDetection(10); Picture effect2 = new Picture(pic2); this.copy(effect1, 250, 600); this.copy(pic2, 0, 600); effect2.mirrorVertical(); this.copy(effect2, 250, 0); this.copy(picNoBlue, 0, 0); this.write("collage.jpg"); }
/* Main method for testing - each class in Java can have a main * method */ public static void main(String[] args) { Picture beach = new Picture("beach.jpg"); beach.explore(); beach.zeroBlue(); beach.explore(); }
/* Main method for testing - each class in Java can have a main * method */ public static void main(String[] args) { Picture beach = new Picture("pixLab/images/beach.jpg"); beach.explore(); beach.keepOnlyRed(); beach.explore(); }