读取处理帧外的像素值

时间:2014-10-19 17:39:47

标签: processing

简短问题:有没有办法在屏幕上读取RGB值的像素外面处理草图显示窗口?

1 个答案:

答案 0 :(得分:2)

您可以使用具有createScreenCapture()方法的java的Robot类。这将以java的最常见图像格式返回图像:java.awt.BufferedImage。

幸运的是处理PImage has a constructor from a java.awt.Image(包括像BufferedImage这样的子类),所以把它们放在一起是非常简单的:

import java.awt.*;
import java.awt.image.BufferedImage;

PImage shot;

void setup(){
  rectMode(CENTER);
  try
  {
    Robot robot = new Robot();
    BufferedImage screenshot =  robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    shot = new PImage(screenshot);
  }catch (AWTException e){
    throw new RuntimeException("Unable to Initialize", e);
  }

}
void draw(){
  image(shot,0,0);
  fill(shot.get(mouseX,mouseY));
  rect(mouseX,mouseY,15,15);
}