Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 图像处理中的image()函数_Image Processing_Processing_Image Resizing - Fatal编程技术网

Image processing 图像处理中的image()函数

Image processing 图像处理中的image()函数,image-processing,processing,image-resizing,Image Processing,Processing,Image Resizing,所以,我尝试裁剪并显示一张图片,我希望每次显示的图片都和屏幕一样大,到目前为止,我有这段代码,但是图像大小每次都会改变,根据API,它应该是全屏的 PImage img; PImage temp; void setup() { size(800, 600); img = loadImage("genevieve-bjargardottir1.jpg"); frameRate(5); } void draw() { background(0); text(frameRate

所以,我尝试裁剪并显示一张图片,我希望每次显示的图片都和屏幕一样大,到目前为止,我有这段代码,但是图像大小每次都会改变,根据API,它应该是全屏的

PImage img;
PImage temp;

void setup() {
  size(800, 600);
  img = loadImage("genevieve-bjargardottir1.jpg");
  frameRate(5);
}

void draw() {
  background(0);
  text(frameRate, 10, 20);

  int x, y, xx, yy;
  x = (int)random(width);
  xx = (int)random(width);
  y = (int)random(height);
  yy = (int)random(height);

  temp = img.get(x, y, xx, yy);

  image(temp, 0, 0, width, height);

}
我想最后一行:

image(temp, 0, 0, width, height);

将向整个窗口显示我裁剪的图像。起点设置为0,终点设置为当前窗口大小的宽度和高度

您将在每一帧(每秒5次)获得图像的随机部分,然后以窗口的全尺寸显示该部分图像。你以为会发生什么?

在阅读@Kevin Workman的建议时,我想到了以下片段:)

PImage-img;
皮梅杰温度;
浮式支柱;
无效设置(){
while(img==null){
img=加载图像(“http://xaxor.com/images/Genevieve-Bjargardottir/Genevieve-Bjargardottir1.jpg");
}
prop=(浮动)img.width/(浮动)img.height;
尺寸(800,内部(800/道具));
帧率(1);
}
作废提款(){
浮动pw=随机(img.宽度);
浮子ph=pw/prop;
int x,y;
x=int(随机(img.width-pw));
y=int(随机(img.高度-ph));
//鳞片
温度=img.get(x,y,int(pw),int(ph));
图像(温度、0、0、宽度、高度);
//全画图
图像(img,0,0,img.width/6,img.height/6);
noFill();
中风(255);
//交叉件
rect(x/6,y/6,pw/6,ph/6);
}

我原以为我得到的零件会显示在整个屏幕上,但那没有发生。您没有使用全屏窗口。您使用的窗口是800x600。宽度和高度变量将给出窗口的大小,而不是屏幕的大小。是的,对不起,我指的是窗口,我希望图像显示在整个窗口中。它是。相反,您生成的图像的随机部分是。如果你想显示整个图像,为什么你会得到一个随机的部分呢?你的方法有一些错误。首先,从屏幕的宽度和高度得到一个随机的x和y。除非您的屏幕与原始图像大小相同,否则无法正常工作。您必须参考原始图像大小。然后,你得到一个随机的宽度和高度,同样基于屏幕大小。你需要以原始图像大小为基础,并且你需要以你选择的随机x和y的宽度和高度为基础:如果你的图像一开始只有800像素宽,你就不能选择750的x和750的宽度。这正是我想要的,很好看,谢谢兄弟!