Download presentation
Presentation is loading. Please wait.
Published byLeslie Webb Modified over 5 years ago
1
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
With a red, green, and blue value stored for each pixel (each has a range from 0 to 255) Stored in .jpg (JPEG) files International standard With “lossy compression” Lossy means not all data is stored But what is lost isn’t that important Compression means made smaller What are some other formats for storing pictures? For more about JPEG see See for more information about GIFF. See for more information about BMP. This windows format is not compressed.
2
Pictures have lots of Pixels
How can we refer to each pixel? pixel1, pixel2, pixel3, pixel4, pixel5, … Do we really want to name each one? There are 640 x 480 = 307,200 pixels How could we deal with all of the pixels in a picture WITHOUT naming each one separately?
3
What is an Array? Storage for a sequence of items
1 2 3 4 5 Storage for a sequence of items Of the same type You can access items by using the index The index starts at 0 The first item is at index 0 The last item is at index (length – 1) Arrays know their length (have a public length field) arrayObj.length 3 7 9 2 1 5 1 2 3 8 3 2 6 Think of seats in a row of a movie theater. They have an index too. They often start at 1. Java uses a 0-based index. This is a holdover from C when the index was really the distance from the beginning of the array. The distance from the beginning of the array to the first element is 0.
4
Manipulating a Picture
To manipulate a picture we need to manipulate the pixels that make up the picture Change the red, green, or blue values at the pixel The Pixel class is not in the Java API!!! Created by the same people who made the Turtle class (Barbara Ga. Tech) Each pixel object has a red, green, and blue value
5
What Information Can A Picture Object Give Us?
Each picture object has an array of pixel objects Read from the JPEG file It knows the picture’s width & height Which methods of SimplePicture do this? How would we call them? It knows how to obtain an array of pixel objects What method of SimplePicture does this? How would we call it?
6
Pixel Objects Each pixel has a red, green, and blue value
getRed(), getGreen(), getBlue() setRed(v), setGreen(v), setBlue(v) Each pixel knows the location it was in the picture object getX(), getY() You can also get and set the color at the pixel getColor(), setColor(color)
7
Color Objects There is a class defined in Java that represents color
The Color class in the package java.awt To use the class you must either import java.awt.Color; Use the full name java.awt.Color You can create a color object by giving the red, green, and blue values for it Color colorObj = new Color(255,10,125);
8
Predefined Colors The Color class has defined class constants for many colors Color.red, Color.green, Color.blue, Color.black, Color.white, Color.yellow, Color.gray, Color.orange, Color.pink, Color.cyan, Color.magenta Or you can use all uppercase names Color.RED, Color.BLUE, Color.BLACK, … Originally the predefined colors where are lowercase names. However, the Java convention for constants is to use all uppercase letters. So the uppercase names for the predefined colors were added.
9
Getting and Setting Pixel Colors
EXAMPLE: Get a pixel’s color as a color object Color color1 = pixelObj.getColor(); int red = color1.getRed(); int green = color1.getGreen(); int blue = color1.getBlue(); EXAMPLE: Set a pixel’s color using a new color object red = 20; green = 30; blue = 100; Color color2 = new Color(red,green,blue); pixelObj.setColor(color2); For pixelObj use whatever the name is of the current pixel object.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.