简体   繁体   English

如何在处理(Java)中使用像素 [] 放大显示?

[英]How to magnify display working with pixels[] in Processing (Java)?

I love experimenting with operating on images pixel by pixel using pixels[] .我喜欢尝试使用pixel[]逐个像素地对图像进行操作。 However, I'd like to work on a matrix of 100x100 pixels but have the display be several times larger than 100x100 on my screen.但是,我想处理一个 100x100 像素的矩阵,但在我的屏幕上显示比 100x100 大几倍。

Is there an efficient and straightforward way to zoom, magnify, scale, resize, or etc… to allow me to work with pixels[] just… bigger?是否有一种有效且直接的方法来缩放、放大、缩放、调整大小等……以允许我使用像素 [] 只是……更大?

I was disappointed to see that scale() doesn't work with pixel arrays.我很失望地看到 scale() 不适用于像素 arrays。

My first idea to scale by a factor of S is by iterating through my pixel array and drawing a board of SxS rect s with the fill of each pixel's color val.我第一个按 S 因子缩放的想法是遍历我的像素数组并绘制一个 SxS rect板,并填充每个像素的颜色值。 However, this is computationally intensive, and I can't get my frameRate above 5 or so.但是,这是计算密集型的,我的 frameRate 不能超过 5 左右。

Ah great idea @sorifiend.啊好主意@sorifiend。 Since I was calling loadPixels() immediately after setting the window size() and leaving it blank (rather than loading pixels from a image and putting it in the window,) I hadn't thought of that.由于我在设置 window size() 并将其留空后立即调用 loadPixels()(而不是从图像中加载像素并将其放入 window,)我没有想到这一点。 I found you can use createImage() to make an empty image, which resizes crisply with noSmooth();我发现你可以使用createImage()来制作一个空图像,它可以用 noSmooth() 清晰地调整大小; on!上! Thanks for the start.谢谢你的开始。

Here's my code for posterity:这是我的后代代码:


void setup() {
  i = createImage(100, 100, RGB);
  background(0);
  size(800, 800);
  i.loadPixels();
  noSmooth();

}

void draw() {
  i.loadPixels();
  for (int x = 0; x < i.width; x++) {
    for (int y = 0; y < i.height; y++) {
      if (random(0,max(i.width,i.height)) < y) {
        i.pixels[x + y*i.height] = color(255);
      } else {
        i.pixels[x + y*i.height] = color(0);
      }
    }
  }
  i.updatePixels();
  image(i,0,0,width,height);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM