/** * Sets the color of a pixel. * * @param x the x-coordinate (column) of the pixel * @param y the y-coordinate (row) of the pixel * @param the color of the pixel at the given row and column */ public void setColorAt(int x, int y, Color color) { if (image == null || x < 0 || x >= image.getWidth() || y < 0 || y >= image.getHeight()) { throw new IndexOutOfBoundsException("(" + x + "," + y + ")"); } else { image.setRGB( x, y, ((int) color.getRed()) * 65536 + ((int) color.getGreen()) * 256 + (int) color.getBlue()); Canvas.getInstance().repaint(); } }
/** * Loads a new image from a given file or URL. * * @param source the filename or URL */ public void load(String source) { try { this.source = source; if (source.startsWith("http://")) image = ImageIO.read(new URL(source).openStream()); else image = ImageIO.read(new File(source)); label.setIcon(new ImageIcon(image)); label.setText(""); } catch (Exception ex) { image = null; label.setIcon(null); ex.printStackTrace(); } Canvas.getInstance().repaint(); }
/** Shows this picture on the canvas. */ public void draw() { Canvas.getInstance().show(this); }
/** * Resizes this picture both horizontally and vertically. * * @param dw the amount by which to resize the width on each side * @param dw the amount by which to resize the height on each side */ public void grow(double dw, double dh) { xGrow += dw; yGrow += dh; Canvas.getInstance().repaint(); }
/** * Moves this picture by a given amount. * * @param dx the amount by which to move in x-direction * @param dy the amount by which to move in y-direction */ public void translate(double dx, double dy) { x += dx; y += dy; Canvas.getInstance().repaint(); }