cs026_6_Part1

cs026_6_Part1 - Topic 5 Part 1 Introduction to Pictures...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Topic 5 Part 1 Introduction to Pictures Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by B. Ericson.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Learning Goals • To understand at a conceptual and practical level: • How to manipulate digital images using various methods • What is an array • How to use arrays
Background image of page 2
3 Java Concepts in this Section • Arrays • Importing classes
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Digital Pictures • Recall that we can represent a digital picture as a grid of pixels • With a red, green, and blue value stored for each pixel
Background image of page 4
5 Pictures Can Have Lots of Pixels • How could we refer to each pixel? pixel1, pixel2, pixel3, pixel4, pixel5, • But, do we really want to name each one? • In a 640 x 480 image, there are 307,200 pixels! • And this is a low resolution image … high quality pictures can have millions and millions of pixels • How do we efficiently deal with lots of data of the same type in Java? • We use something called an array …
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 What is an Array? • An array is storage for a collection of items of the same type • You can access the items by using an index • The index starts at 0 • The first item is at index 0 • The last item is at index (length – 1) 3 7 9 2 1 5 0 1 2 3 4 5 Example: int array of length 6 What value is stored at index 0? at index 4?
Background image of page 6
7 What is an Array? • In Java, an array is an object • We begin by declaring a reference variable, and then we create the array Array reference variables are declared by type[ ] name; • Example: int[ ] numbers; • This creates a reference variable called numbers that can be used to refer to an array of integers • But this does not actually create the array …
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Creating Arrays • Creating an array is much like creating other objects in Java … we use new to do so • Example: numbers = new int[5]; • This now creates an array of 5 integers, and has the reference variable numbers refer to it • The reference variable numbers refers to the entire collection of integers (we will see how to refer to individual items shortly) • This does not store anything in the array Once we create an array, its size is fixed and we cannot change it
Background image of page 8
9 Initializing Arrays • We can declare, create, and initialize an array in one statement • Example: int[ ] numbers = { 3, 7, 9, 2, 1, 5 }; • This creates an array of 6 integers, and sets the
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/20/2009 for the course COMP SCI 026 taught by Professor Unknown during the Spring '07 term at UWO.

Page1 / 30

cs026_6_Part1 - Topic 5 Part 1 Introduction to Pictures...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online