不使用局部变量“img”的值

问题描述 投票:1回答:2

我正在运行编码列车教程。但是按照他的指示,我一直都会收到错误。有人能告诉我我的代码有什么问题吗?

import org.openkinect.processing.*;

Kinect kinect;

void setup() {

    PImage img; 

    size(512, 484); 
    kinect = new Kinect(this); 
    kinect.initDepth(); 
    img = createImage(kinect.width, kinect.height, RGB); 

}  

void draw() { 
    background(0); 

    img.loadPixels(); 

    int[] depth = kinect.getRawDepth(); 

    for (int x = 0; x < kinect.width; x++) { 
        for (int y = 0; y < kinect.height; y++) {
            int offsett = x + y * kinect.width; 
            int d = depth[offsett]; 

            img.pixels[offset] = color(255,0,150);
        }
    }

    img.updatePixels(); 
    image(img, 0, 0);
}

谢谢您的帮助!

processing kinect
2个回答
1
投票

您在setup()函数中定义了变量img,因此该变量的范围仅为该方法。

你在draw()函数中多次使用变量img,但是你从未在该函数中定义过一个。

我会说错误是两个函数中具有相同变量名称的混淆。


-2
投票

尝试更改相同变量的名称,这不是一个好方法,也许这是错误的原因。

© www.soinside.com 2019 - 2024. All rights reserved.