Chap 04 Multimedia Picture is tinted color PImage

  • Slides: 17
Download presentation
Chap 04 Multimedia

Chap 04 Multimedia

Picture is tinted color PImage b; size(640, 240); b = load. Image("landscape. png"); tint(100,

Picture is tinted color PImage b; size(640, 240); b = load. Image("landscape. png"); tint(100, 0, 100); // Tint purple image(b, 0, 0, 320, 200); no. Tint(); // Disable tint image(b, 320, 0, 320, 200); <Reference> 可改變長寬比

Play movie repeatedly import processing. video. *; Movie my. Movie; void setup() <試試看> 是否可用其他模式

Play movie repeatedly import processing. video. *; Movie my. Movie; void setup() <試試看> 是否可用其他模式 { size(180, 160, P 2 D); background(0); my. Movie = new Movie(this, "station. mov"); my. Movie. loop(); } void draw() {image(my. Movie, 0, 0); } void {void movie. Event(Movie m) {m. read(); } 第二種作法 if(my. Movie. available()) my. Movie. read(); image(my. Movie, 0, 0); }

Control playing speed of movie import processing. video. *; Movie my. Movie; int fps=15;

Control playing speed of movie import processing. video. *; Movie my. Movie; int fps=15; float rate=1; void setup() { size(180, 160, P 2 D); background(0); my. Movie = new Movie(this, "station. mov"); my. Movie. loop(); } void draw() {image(my. Movie, 0, 0); } void movie. Event(Movie m) {m. read(); } void mouse. Pressed() { if(mouse. Button==LEFT) {fps--; rate-=0. 1; } else if(mouse. Button==RIGHT) {fps++; rate+=0. 1 f; } if(fps<1) fps=1; my. Movie. frame. Rate(fps); //my. Movie. speed(rate); println("FPS: "+fps+" RATE: "+rate); }

Audio n n 注意:外部Library import ddf. minim. *; http: //code. compartmental. net/tools/minim/m anual-minim

Audio n n 注意:外部Library import ddf. minim. *; http: //code. compartmental. net/tools/minim/m anual-minim

Play music file import ddf. minim. *; Minim minim; Audio. Player in; void setup()

Play music file import ddf. minim. *; Minim minim; Audio. Player in; void setup() { minim = new Minim(this); in = minim. load. File("groove. mp 3"); // load a file, default sample buffer size is 1024 in. play(); // play the file } void draw(){} void stop() { in. close(); // always close audio I/O classes minim. stop(); // always stop your Minim object super. stop(); }

Create sound import ddf. minim. *; import ddf. minim. signals. *; Minim minim; Audio.

Create sound import ddf. minim. *; import ddf. minim. signals. *; Minim minim; Audio. Output out; Sine. Wave sine; void setup() { minim = new Minim(this); out = minim. get. Line. Out(Minim. STEREO, 512); // get a line out from Minim, default sample rate is 44100, bit depth is 16 sine = new Sine. Wave(440, 0. 5, 44100); // create a sine wave Oscillator, set to 440 Hz, at 0. 5 amplitude, sample rate 44100 to match the line out. add. Signal(sine); // add the oscillator to the line out } void draw(){} void stop() { out. close(); minim. stop(); super. stop(); }

Audio recorder import ddf. minim. *; Minim minim; Audio. Input in; Audio. Recorder fout;

Audio recorder import ddf. minim. *; Minim minim; Audio. Input in; Audio. Recorder fout; void setup() { minim = new Minim(this); in = minim. get. Line. In(Minim. STEREO, 512); fout = minim. create. Recorder(in, "record. wav", true); // get a recorder that will record from in to the filename specified using buffered recording } void key. Released() { if(key=='b') fout. begin. Record(); else if(key=='e') fout. end. Record(); else if(key=='s') fout. save(); } void draw(){} void stop() { in. close(); minim. stop(); super. stop(); }

Get sound from mic or line-in n 程式碼

Get sound from mic or line-in n 程式碼

影像處理 n n PImage Fields q q q n 補充:主程式視窗就是一個Image width- Image width height

影像處理 n n PImage Fields q q q n 補充:主程式視窗就是一個Image width- Image width height - Image height pixels[]- Array containing the color of every pixel in the image Methods q q q q q get() - Reads the color of any pixel or grabs a rectangle of pixels set() - Writes a color to any pixel or writes an image into another copy() - Copies the entire image mask() - Masks part of the image from displaying blend() - Copies a pixel or rectangle of pixels using different blending modes filter() - Converts the image to grayscale or black and white save() - Saves the image to a TIFF, TARGA, PNG, or JPEG file resize() - Changes the size of an image to a new width and height load. Pixels() - Loads the pixel data for the image into its pixels[] array update. Pixels() - Updates the image with the data in its pixels[] array

Copy Image & Screen Image size(700, 480); background(255); PImage img = load. Image("landscape. png");

Copy Image & Screen Image size(700, 480); background(255); PImage img = load. Image("landscape. png"); img. copy(0, 0, 40, 80, 600, 0, 40, 80); image(img, 60, 0); size(700, 480); background(255); PImage img = load. Image("landscape. png"); image(img, 60, 0); copy(0, 0, 40, 80, 600, 0, 40, 80); 順序對調 去掉指定的image 試試看:比較兩者的不同

Image Mask PImage img; PImage mask. Img; size(500, 300); background(255); img = load. Image("bear.

Image Mask PImage img; PImage mask. Img; size(500, 300); background(255); img = load. Image("bear. jpg"); mask. Img = load. Image("mask. jpg"); image(img, 50); img. mask(mask. Img); image(img, 250, 50);

Image Filter PImage img; PImage mask. Img; size(700, 500); background(255); //原圖 img = load.

Image Filter PImage img; PImage mask. Img; size(700, 500); background(255); //原圖 img = load. Image("bear. jpg"); image(img, 50); //黑白, 參數為黑白門檻 img = load. Image("bear. jpg"); img. filter(THRESHOLD, 0. 8); image(img, 250, 50); //灰階 img = load. Image("bear. jpg"); img. filter(GRAY); image(img, 450, 50); //反色 img = load. Image("bear. jpg"); img. filter(INVERT); image(img, 50, 250); //模糊, 參數為模糊程度 img = load. Image("bear. jpg"); img. filter(BLUR, 5); image(img, 250); //色階, 參數為顏色bit數 img = load. Image("bear. jpg"); img. filter(POSTERIZE, 4); image(img, 450, 250);

Image Blend PImage img; PImage mask. Img; size(700, 500); background(255); img = load. Image("bear.

Image Blend PImage img; PImage mask. Img; size(700, 500); background(255); img = load. Image("bear. jpg"); mask. Img = load. Image("child. jpg"); img. blend(mask. Img, 0, 0, 68, 200, 132, 0, 68, 200, ADD); image(mask. Img, 132, 0); image(img, 0, 0); img = load. Image("bear. jpg"); mask. Img = load. Image("child. jpg"); img. blend(mask. Img, 0, 0, 68, 200, 132, 0, 68, 200, SUBTRACT); image(mask. Img, 482, 0); image(img, 350, 0); img = load. Image("bear. jpg"); mask. Img = load. Image("child. jpg"); img. blend(mask. Img, 0, 0, 68, 200, 132, 0, 68, 200, DARKEST); image(mask. Img, 132, 200); image(img, 0, 200); img = load. Image("bear. jpg"); mask. Img = load. Image("child. jpg"); img. blend(mask. Img, 0, 0, 68, 200, 132, 0, 68, 200, LIGHTEST); image(mask. Img, 482, 200); image(img, 350, 200); <Reference> PImage->Blend

Image Pixel PImage img; int dimension; float cr, cg, cb; int threshold=50; void setup()

Image Pixel PImage img; int dimension; float cr, cg, cb; int threshold=50; void setup() { size(200, 200); img = load. Image("bear. jpg"); dimension = (img. width*img. height); cr=cg=cb=-1; } void draw() { background(200, 0, 0); img. load. Pixels(); for (int i=0; i < dimension; i++) { if(abs(red(img. pixels[i])-cr)<threshold && abs(green(img. pixels[i])-cg)<threshold && abs(blue(img. pixels[i])-cb)<threshold) img. pixels[i] = color(255); } img. update. Pixels(); image(img, 0, 0); } void mouse. Pressed() { load. Pixels(); int cho=pixels[mouse. X+mouse. Y*width]; cr=red(cho); cg=green(cho); cb=blue(cho); println("Red: "+cr+" Green: "+cg+" Blue: "+cb); } 此種作法稱為Chroma Key或去背