{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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.
Image of page 1

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

View Full Document Right 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
Image of page 2
3 Java Concepts in this Section • Arrays Importing classes
Image of page 3

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

View Full Document Right 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
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 …
Image of page 5

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

View Full Document Right 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?
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 …
Image of page 7

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

View Full Document Right 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
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 };
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern