Package org.cis1200

Class PixelPicture

java.lang.Object
org.cis1200.PixelPicture

public class PixelPicture extends Object
An image represented by a 2D array of Pixels. PixelPictures are immutable. Although they provide access to a 2D array of pixels, this array is a copy of the one stored in the NewPic. The original image cannot be modified.
  • Constructor Details

    • PixelPicture

      public PixelPicture(PixelPicture other)
      Copies a NewPic.
      Parameters:
      other - NewPic the other NewPic to copy
    • PixelPicture

      public PixelPicture(String filename)
      Creates a NewPic by loading the given file or URL.
      Parameters:
      filename - the location of the image file to read
    • PixelPicture

      public PixelPicture(Pixel[][] bmp)
      Creates a picture given a bitmap. The bitmap should be in left-to-right, top-to-bottom ordering.
      Parameters:
      bmp - The bitmap
  • Method Details

    • getWidth

      public int getWidth()
      Returns:
      the width of the image.
    • getHeight

      public int getHeight()
      Returns:
      the height of the image.
    • getBitmap

      public Pixel[][] getBitmap()
      Gets a bitmap (i.e., matrix of pixels) of the image. This method returns a copy of the image's contents---editing the returned bitmap will not affect the NewPic. The bitmap is in a top-to-bottom, left-to-right order. The first index is the row, the second index is the column. That way, a pixel at coordinate (x,y) can be accessed as bmp[y][x].
      Returns:
      a top-to-bottom, left-to-right order array of arrays of Pixels
    • toImageIcon

      public ImageIcon toImageIcon()
      Creates an ImageIcon, suitable for display by Swing components.
      Returns:
      ImageIcon pointing at a copy of this image
    • diff

      public static int diff(PixelPicture p0, PixelPicture p1)
      Compute the difference between two images. This difference sums the pixel-by-pixel differences between components of a pixel. It is most useful for SMALL images.
      Parameters:
      p0 - first image to compare
      p1 - second image to compare
      Returns:
      sum of all differences between pixel components
    • print

      public void print()
      Print all of the pixels in the image to the console. This is debugging aid. Only use this method for SMALL images.
    • save

      public void save(String filename)