好的,我需要让程序扫描屏幕以获得某个 rgb 值,然后将其更改为亮粉色。我制作了这个程序,到目前为止它会扫描屏幕上的某种颜色。我不知道如何让它改变像素颜色。我想我需要上传图片而不是让它扫描屏幕。但如果我这样做,我仍然不知道如何改变像素。
到目前为止,这是我的代码。
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.awt.image.WritableRaster;
public class FindRgbOnScreen extends Thread{
public Rectangle captureSize;
public FindRgbOnScreen() {
captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}
public void run() {
try {
Robot robot = new Robot();
while(true){
BufferedImage img = robot.createScreenCapture(captureSize);
WritableRaster r = img.getRaster();
DataBuffer db = r.getDataBuffer();
DataBufferInt dbi = (DataBufferInt)db;
int[] data = dbi.getData();
for (int x_scale = 0; x_scale < captureSize.width; x_scale += 1) { //this scans the screen
for(int y_scale = 0; y_scale < captureSize.height; y_scale += 1) {
int rgb = data[x_scale + captureSize.width * y_scale];
if (rgb == -5381164){
//change pixel to pink
}
else{
//change pixel to grey
}
}
}
}
}
catch(AWTException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new FindRgbOnScreen().start();
}
}