【Processing】生成图片code(用于显示器画质测试)

1 纯色

指定某个屏幕,全屏纯色,颜色可自由设定。

java 复制代码
//全局变量定义
PFont f;
//boolean ip_en=true;  // comp enable ,   on set by 'q',   off set by'w'
int BG_R=128; //back ground gray,like 192,160,148,128
int BG_G=128; //back ground gray,like 192,160,148,128
int BG_B=128; //back ground gray,like 192,160,148,128

//初始化设置
void setup() {

  f = createFont("Arial", 16, true);//字体样式
  textFont(f, 50);    //字体颜色
  fill(255);     //字体颜色
  fullScreen(2);  //第几个屏幕全屏
}


// 按键触发
//按 s 保存画面
void keyPressed () {
    //if (key == 'q')  ip_en=!ip_en;
    //保存画面
      if (key == 's' || key == 'S') {
    saveFrame("output/screen_####.png");    // 用saveFrame自动编号,不会覆盖旧图,Processing 项目文件夹内自动生成 output 文件夹
    println("截图已保存到项目output文件夹");
       }
       
            
}
//绘制设计
void draw () {
  loadPixels();
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      int loc = x+y*width;

      pixels[loc] = color(120, 0, 0);
      // if(y==height/2)pixels[loc] = color(0, 0, 0);
            
    }
  }

  updatePixels();
 // if (ip_en == true) text("IP_ON", 200, 80);
 // else           text("IP_OFF", 200, 80); 
    
  text("Background:  ", 200, 120);
  text( BG_R, 500, 120);
  text( width, 500, 240);
   text( height, 900,240);
}

2 串扰

2.1 pixel/Dot on off

java 复制代码
//全局变量定义
PFont f;
//boolean ip_en=true;  // comp enable ,   on set by 'q',   off set by'w'
int BG_R=128; //back ground gray,like 192,160,148,128
int BG_G=128; //back ground gray,like 192,160,148,128
int BG_B=128; //back ground gray,like 192,160,148,128
int BG_left=200;
int BG_right= BG_left;

//初始化设置
void setup() {

  f = createFont("Arial", 16, true);//字体样式
  textFont(f, 50);    //字体颜色
  fill(255);     //字体颜色
  fullScreen(2);  //第几个屏幕全屏
}


// 按键触发
//按 s 保存画面
void keyPressed () {
    //if (key == 'q')  ip_en=!ip_en;
    //保存画面
      if (key == 's' || key == 'S') {
    saveFrame("output/screen_####.png");    // 用saveFrame自动编号,不会覆盖旧图,Processing 项目文件夹内自动生成 output 文件夹
    println("截图已保存到项目output文件夹");
       }
       
            
}
//绘制设计
void draw () {
  loadPixels();
  background(BG_R, BG_G, BG_B);//设置背景颜色

     for (int y=100;y<height;y+=100){
           for (int x =  BG_left; x < width- BG_right; x+=2) {
                   int loc = x+y*width;
                   pixels[loc] = color(0, 0, 0);// pixel(0,0,0),dot(0,255,0)
           }
           for (int x =  BG_left+1; x < width- BG_right; x+=2) {
                   int loc = x+y*width;
                   pixels[loc] = color(255, 255, 255);// pixel(255,255,255),dot(255,0,255)
           } 
    }
  
  //for (int y = 0; y < height; y++) {
  //  for (int x = 0; x < width; x++) {
  //    int loc = x+y*width;
  //   // pixels[loc] = color(120, 0, 0);
  //   for (int k=100;k<height;k+=100){
  //    if(y==K)pixels[loc] = color(0, 0, 0);
  //  }
            
  //  }
  //}
  updatePixels();
 // if (ip_en == true) text("IP_ON", 200, 80);
 // else           text("IP_OFF", 200, 80); 
    
  //text("Background:  ", 200, 120);
  //text( BG_R, 500, 120);
  //text( width, 500, 240);
  // text( height, 900,240);
}

3 OPR

4 常见问题

【已解决】只会显示一部分画面,与实际分辨率不符合

系统缩放不是 100%。Windows 默认会开 125%/150% 缩放,Processing 是老式 Java 程序,不支持 DPI 感知。

解决方法:

1)找到 Processing 快捷方式 → 右键属性 → 兼容性'

2)勾选「替代高 DPI 缩放行为」,下拉选 系统 (增强);

3)确定后重启 Processing,画布会按真实物理像素渲染,不会被缩放压缩;