|
楼主 |
发表于 2012-8-11 14:30:31
|
显示全部楼层
T T。。以自己解决。。。弱智贴就不删了。。给其他人个警示。。
出现错误的原因是图片和画布区域大小不一样。。对于画布和图片的像素位置应该分别计算。附上改后的代码:- PImage img;
- void setup() {
- size(500,500);
- img = loadImage("bird.jpg");
- }
- void draw() {
- loadPixels();
-
- img.loadPixels();
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- int imageLoc = x + y*img.width;
- int displayLoc = x + y*width;
-
- float r = red(img.pixels[imageLoc]);
- float g = green(img.pixels[imageLoc]);
- float b = blue(img.pixels[imageLoc]);
-
- pixels[displayLoc] =color(r,g,b);
-
- }
- }
- updatePixels();
- }
复制代码 |
|