Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chap 04 Multimedia. Image PImage -儲存 image 的資料型別 loadImage(URL) -從 URL( 包含本地路徑 ) 載 入圖片 image(Image,X, Y) -在座標 (X,Y) 顯示 Image tint(R,G,B) -將要顯示的圖片染成指定的顏色.

Similar presentations


Presentation on theme: "Chap 04 Multimedia. Image PImage -儲存 image 的資料型別 loadImage(URL) -從 URL( 包含本地路徑 ) 載 入圖片 image(Image,X, Y) -在座標 (X,Y) 顯示 Image tint(R,G,B) -將要顯示的圖片染成指定的顏色."— Presentation transcript:

1 Chap 04 Multimedia

2 Image PImage -儲存 image 的資料型別 loadImage(URL) -從 URL( 包含本地路徑 ) 載 入圖片 image(Image,X, Y) -在座標 (X,Y) 顯示 Image tint(R,G,B) -將要顯示的圖片染成指定的顏色 noTint() -取消染色設定 Background(Image) -將 Image 顯示為背景, 大小需要和視窗一樣大

3 Picture is tinted color PImage b; size(640,240); b = loadImage("landscape.png"); tint(100, 0,100); // Tint purple image(b, 0, 0,320,200); noTint(); // Disable tint image(b, 320,0,320,200); 可改變長寬比

4 Video Movie -儲存影片的資料型別 Methods  read() -讀取影片資料  available() - boolean ,確認影片資料是否可讀取  play() -播放一次影片  loop() -不斷播放影片  pause() -暫停播放影片  stop() -停止播放影片  noLoop() -若目前是 loop 狀態,則播放結束後就不繼續播  jump(Second) -跳到 Second 秒數的位置播放  duration() - float ,以秒數表示影片總長度  time() - float ,以秒數表示目前影片已播放的時間  speed(Rate) -設定播放速度, Rate=1 為正常, Rate>1 則變快, 1>Rate>0 則變慢, Rate=-1 則倒轉  frameRate(FPS) -設定一秒鐘播放 FPS 個畫面 注意:外部 Library import processing.video.*;

5 Play movie repeatedly import processing.video.*; Movie myMovie; void setup() { size(180,160,P2D); background(0); myMovie = new Movie(this, "station.mov"); myMovie.loop(); } void draw() {image(myMovie, 0, 0);} void movieEvent(Movie m) {m.read();} 是否可用其他模式 void draw() { if(myMovie.available()) myMovie.read(); image(myMovie, 0, 0); } 第二種作法

6 Control playing speed of movie import processing.video.*; Movie myMovie; int fps=15; float rate=1; void setup() { size(180,160,P2D); background(0); myMovie = new Movie(this, "station.mov"); myMovie.loop(); } void draw() {image(myMovie, 0, 0);} void movieEvent(Movie m) {m.read();} void mousePressed() { if(mouseButton==LEFT) {fps--;rate-=0.1;} else if(mouseButton==RIGHT) {fps++;rate+=0.1f;} if(fps<1) fps=1; myMovie.frameRate(fps); //myMovie.speed(rate); println("FPS: "+fps+" RATE: "+rate); }

7 Audio http://code.compartmental.net/tools/minim http://code.compartmental.net/tools/minim/ma nual-minim 注意:外部 Library import ddf.minim.*;

8 Play music file import ddf.minim.*; Minim minim; AudioPlayer in; void setup() { minim = new Minim(this); in = minim.loadFile("groove.mp3"); // 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(); }

9 Create sound import ddf.minim.*; import ddf.minim.signals.*; Minim minim; AudioOutput out; SineWave sine; void setup() { minim = new Minim(this); out = minim.getLineOut(Minim.STEREO, 512); // get a line out from Minim, default sample rate is 44100, bit depth is 16 sine = new SineWave(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 out.addSignal(sine); // add the oscillator to the line out } void draw(){} void stop() { out.close(); minim.stop(); super.stop(); }

10 Audio recorder import ddf.minim.*; Minim minim; AudioInput in; AudioRecorder fout; void setup() { minim = new Minim(this); in = minim.getLineIn(Minim.STEREO, 512); fout = minim.createRecorder(in, "record.wav", true); // get a recorder that will record from in to the filename specified using buffered recording } void keyReleased() { if(key=='b') fout.beginRecord(); else if(key=='e') fout.endRecord(); else if(key=='s') fout.save(); } void draw(){} void stop() { in.close(); minim.stop(); super.stop(); }

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

12 影像處理 PImage Fields  width - Image width  height - Image height  pixels[] - Array containing the color of every pixel in the image Methods  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  loadPixels() - Loads the pixel data for the image into its pixels[] array  updatePixels() - Updates the image with the data in its pixels[] array 補充:主程式視窗就是一個 Image

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

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

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

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

17 Image Pixel PImage img; int dimension; float cr,cg,cb; int threshold=50; void setup() { size(200,200); img = loadImage("bear.jpg"); dimension = (img.width*img.height); cr=cg=cb=-1; } void draw() { background(200,0,0); img.loadPixels(); 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.updatePixels(); image(img, 0,0); } void mousePressed() { loadPixels(); int cho=pixels[mouseX+mouseY*width]; cr=red(cho); cg=green(cho); cb=blue(cho); println("Red: "+cr+" Green: "+cg+" Blue: "+cb); } 此種作法稱為 Chroma Key 或去背


Download ppt "Chap 04 Multimedia. Image PImage -儲存 image 的資料型別 loadImage(URL) -從 URL( 包含本地路徑 ) 載 入圖片 image(Image,X, Y) -在座標 (X,Y) 顯示 Image tint(R,G,B) -將要顯示的圖片染成指定的顏色."

Similar presentations


Ads by Google