How to use the Java class libraries Brief documentation of how to do this all with Java.

Slides:



Advertisements
Similar presentations
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
Advertisements

Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1.
Problem Solving with Data Structures using Java: A Multimedia Approach Chapter 3: Methods in Java: Manipulating Pictures.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology August 2005.
CS 102 Computers In Context (Multimedia)‏ 02 / 25 / 2009 Instructor: Michael Eckmann.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
Manipulating Pictures CS1316: Representing Structure and Behavior.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
CSE 8A Lecture 8 Reading for next class: None Prepare for In-term exam 2 PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
TOPIC 7 MODIFYING PIXELS IN A MATRIX NESTED FOR LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Pictures Looping through pixels.. Lab Review (1) Objects  Instantiated from Class  Turtle myTut = new Turtle(myWorld);  new operator creates an instance.
Jeopardy Heading1Heading2Heading3Heading4 Heading5 Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
UsingSoundRanges-part21 Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Digital Pictures Represented by pixels –With a red, green, and blue value stored for each pixel (each has a range from 0 to 255) Stored in.jpg (JPEG) files.
ManipulatingPictures-Mod6-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-part41 Nested Loops – part 4 Barb Ericson Georgia Institute of Technology Nov 2009.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
CSC1401 Manipulating Pictures. What we have done to date We have modified pictures by writing on top of them Using Turtles and using Graphics Drawing.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Copyright © Curt Hill Further Picture Manipulation Considering position.
CSC 112Introduction to Media Computation 1 Rotating Images.
CS1315: Introduction to Media Computation Transforming pictures by index number.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
Barbara Ericson Georgia Tech Sept 2005
Manipulating Pictures, Arrays, and Loops part 1
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Topic 6 Modifying Pictures Using Loops
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
Workshop for Programming And Systems Management Teachers
Manipulating Pictures
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Workshop for Programming And Systems Management Teachers
Two-Dimensional Arrays and Nested Loops – part 5
Manipulating Pictures
Manipulating Pictures, Arrays, and Loops part 1
Other displays Saving Arrays Using fors to process
Two-Dimensional Arrays and Nested Loops – part 4
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
Processing Sound Ranges part 2
Digital Pictures Represented by pixels Stored in .jpg (JPEG) files
CSC1401 Viewing a picture as a 2D image - 2
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Presentation transcript:

How to use the Java class libraries Brief documentation of how to do this all with Java.

Java materials We’re developing Java versions of our Media Computation materials for the teachers workshops that we’re developing. Original classes by Guzdial for Jython, revised by students, and now made readable by Barb Ericson

Using DrJava

Basic picture opening & showing > String fileName = FileChooser.pickAFile(); > System.out.println(fileName); C:\intro-prog-java\mediasources\catapillarClipart.jpg > Picture picture=new Picture(fileName); > picture.show(); > System.out.println(picture); Picture, filename C:\intro-prog-java\mediasources\catapillarClipart.jpg height 181 width 360

Methods of Pictures show() repaint() explore() – opens a Picture explorer Pixel [] getPixels() Pixel getPixel(x,y) int getWidth() int getHeight() writePictureTo(filename)

Methods of Pixels int getGreen(), getRed(), getBlue() setGreen(value), setRed(value), setBlue(value) Color getColor() setColor(color) int getX(), getY()

Methods of Color new Color(red, green, blue) ColorChooser.pickAColor() SimplePicture.getColorDistance(color1,color2) color.darker(), color.brighter()

decreaseRed in Java /** * Method to decrease the red by half in the current picture */ public void decreaseRed() { Pixel[] pixels = this.getPixels(); Pixel p = null; int value = 0; // loop through all the pixels for (int i = 0; i < pixels.length; i++) { // get the current pixel p = pixels[i]; // get the value value = p.getRed(); // set the red value to half what it was p.setRed((int) (value * 0.5)); }

/** * Method to copy Katie rotated to the left 90 degrees the picture after Katie has been copied and rotated to the left 90 */ public static Picture copyKatieSideways() { String sourceFile = Picture.getMediaPath("KatieFancy.jpg"); Picture sourcePicture = new Picture(sourceFile); String targetFile = Picture.getMediaPath("7inx95in.jpg"); Picture targetPicture = new Picture(targetFile); Pixel sourcePixel = null; Pixel targetPixel = null; // loop through the columns for (int sourceX = 0, targetX=0; sourceX < sourcePicture.getWidth(); sourceX++, targetX++) { // loop through the rows for (int sourceY = 0, targetY =0; sourceY < sourcePicture.getHeight(); sourceY++, targetY++) { // set the target pixel color to the source pixel color sourcePixel = sourcePicture.getPixel(sourceX,sourceY); targetPixel = targetPicture.getPixel(targetY,targetX); targetPixel.setColor(sourcePixel.getColor( )); } // show the source and target pictures sourcePicture.show(); targetPicture.show(); return targetPicture; }

Basic sound opening & playing > Sound mySound = new Sound(FileChooser.pickAFile()); > mySound.play() > mySound Sound file: thisisatest.wav length: > int asample = mySound.getSample(1); > asample 6852 > mySound.setSample(1,-17); > mySound.getSample(1) -17

Sound methods aren’t as clean yet They’re still in the form we’ve used them in Jython, not as Barb has been making them for Java.

decreaseVolume /** Method to decrease volume by 50% * */ public void decreaseVolume() { int mySample = 0; for (int index = 0; index < getLengthInFrames()-1; // getLengthInFrames currently one too long index++) { try { mySample = getSample(index); // getSample 0-based mySample *= 0.5; setSample(index, (int) mySample); } catch (SoundException ex) { System.out.println("SoundExcepti on occured"); }

Example using decreaseVolume > Sound mySound = new Sound(FileChooser.pickAFile()); > mySound Sound file: thisisatest.wav length: > mySound.getSample(1) 6852 > mySound.getLengthInFrames() > mySound.decreaseVolume(); > mySound.play() > mySound.getSample(1) 3426