Package org.cis1200
Class PixelPicture
java.lang.Object
org.cis1200.PixelPicture
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 Summary
ConstructorsConstructorDescriptionPixelPicture
(String filename) Creates a NewPic by loading the given file or URL.PixelPicture
(Pixel[][] bmp) Creates a picture given a bitmap.PixelPicture
(PixelPicture other) Copies a NewPic. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
diff
(PixelPicture p0, PixelPicture p1) Compute the difference between two images.Pixel[][]
Gets a bitmap (i.e., matrix of pixels) of the image.int
int
getWidth()
void
print()
Print all of the pixels in the image to the console.void
Creates an ImageIcon, suitable for display by Swing components.
-
Constructor Details
-
PixelPicture
Copies a NewPic.- Parameters:
other
- NewPic the other NewPic to copy
-
PixelPicture
Creates a NewPic by loading the given file or URL.- Parameters:
filename
- the location of the image file to read
-
PixelPicture
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
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
Creates an ImageIcon, suitable for display by Swing components.- Returns:
- ImageIcon pointing at a copy of this image
-
diff
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 comparep1
- 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
-