| [Page 126 (continued)] |
In this chapter, we talk about several kinds of encodings of data (or objects).
An object that holds red, green, and blue values, each between 0 and 255.
Pictures are encodings of images, typically coming from a JPEG file or a bitmap (.bmp) file.
A pixel is a dot in a Picture object. It has a color (red, green, and blue) and an (x, y) position associated with it. It remembers its own Picture object so that a change to the pixel changes the real dot in the picture.
This method returns the height of the Picture object in pixels.
getPixel(int x, int y)
This method takes an x position and a y position (two numbers), and returns the Pixel object at that location in the Picture object it is invoked on.
Returns a one-dimensional array of Pixel objects in the Picture object it is invoked on.
This method returns the width of the Picture object in pixels.
This method takes a file name (a string) as input, then writes the Picture object to the file as a JPEG. (Be sure to end the filename in ".jpg" or ".bmp" for the operating system to understand it well.)
Returns the Color object for the Pixel object.
getred(), getGreen(), getBlue()
Each method returns the value (between 0 and 255) of the amount of redness, greenness, and blueness (respectively) in the Pixel object.
This method returns the x or y (respectively) position of where that Pixel object is in the picture.
This method takes a Color object and sets the color for the Pixel object.
setRed(int value), setGreen(int value), setBlue(int value)
Each method takes a value (between 0 and 255) and sets the redness, greenness, or blueness (respectively) of the Pixel object to the given value.
new Color(int red,int green, int blue)
Takes three inputs: the red, green, and blue values (in that order), then creates and returns a Color object.
The methods return a slightly darker or lighter (respectively) version of the Color object.
Displays a window with ways to pick a color. Find the color you want, and the method will return the Color object that you picked.
There are a bunch of constants that are useful in this chapter. These are variables with pre-defined values. These values are colors: Color.black, Color.white, Color.blue, Color.red, Color.green, Color.gray, Color.darkGray, Color.pink, Color.yellow, Color.orange, Color.lightGray, Color.magenta, Color.cyan. You can also use Color.BLACK, Color.WHITE, and so on. Notice that these are not method calls but are public class variables (fields) so they can be accessed using ClassName.fieldName.