2013-02-04 22 views
0

我是Processing的新手,並且一直在玩弄它的功能,但無法爲我的生活想出如何正確調整圖像的大小。下面是一個函數的例子,從教程中,但我似乎無法正確調整圖像的大小,使它適合窗口,任何人有任何建議?eclipse中的Processing2中調整圖像的大小java

import processing.core。*;

public class Adjusting_image_brightness extends PApplet 
{ 
    //intiallize image 
    PImage img; 
    public void setup() 
    { 
     //set the size 
     size(320,240); 
     //load the image 
     img = loadImage("Conn4Board2.jpg");  
     //img.resize(400, 400); 

    } 
    public void draw() 
    { 
     //call the pixels 
     loadPixels(); 
     //run through the pixels 
     for(int x = 0; x < img.width; x++) 
     { 
      for(int y = 0; y <img.height ; y++) 
      { 
       //calculate the 1D pixel location 
       int loc = x + y*width; 
       //get the R G B values from the picture 
       float r = red(img.pixels[loc]); 
       float b= blue(img.pixels[loc]); 
       float g = green(img.pixels[loc]); 

       //change the brightness acording to the mouse here 
       double adjustBrightness = ((float) mouseX/width) * 8.0; 
       r *= adjustBrightness; 
       b *= adjustBrightness; 
       g *= adjustBrightness; 


        //Constrainr RGB to between 0 - 255 
        r = constrain(r, 0 , 255); 
        g = constrain(g, 0 , 255); 
        b = constrain(b, 0, 255); 

        //make a new colour and set pixel in the window 
        int c = color(r,g,b); 
        pixels[loc] = c; 

      } 
     } 
     updatePixels(); 
    } 
} 

謝謝 Stephen。

+0

在一個不重要的筆記上,您在技術上編寫使用Processing API的Java程序,而不是Processing程序。 (純處理程序有一個簡單的編程模型,比如沒有可視化規則,由於所有代碼都在一個類內部結束而導致全局變量,技術上沒有對Java庫的訪問,儘管實際上當在JVM中運行時,程序將會有) –

回答

0

如果您只想調整圖像大小以適應窗口,則代碼太多。該圖像()功能已經讓你說這應該符合在邊界框,所以就用這個:

image(img, 0, 0, width, height); 

和你的形象將吸引縮放到合適。

+0

嗨邁克,這並不完美,因爲它隻影響它的顯示方式。我正在查看調整圖像大小以進行處理。但Resize()。根本沒有工作..顯然這是一個沒有問題。不管怎麼說,還是要謝謝你。 – Steve