2017-07-20 55 views
-1

我每次运行不同的草图时都有新的文件夹,其中包含在我的草图数据文件夹中创建的图像。我需要找到一种方法来加载最近创建的文件夹中的最新图像。它看起来像这样:http://imgur.com/a/0PIsJ(test2是最近创建的)
我将如何使用Pimage来完成此操作?如何加载使用Pimage创建的最新文件夹?

我目前使用我的素描代码:

final int len=25; 
final float thresh=170; 

final int STEPX=18; 
final int STEPY=18; 

boolean newDesign=false; 
PImage pic; 

ArrayList<PImage> imgContainer; 
int n=3; 

void setup() { 
size(800, 800, P2D); 
colorMode(RGB, 255); 
rectMode(CENTER); 
//imageMode(CENTER); 

pic=loadImage("hand.jpg"); 
pic.resize(width, height); 

color c1 = color(200, 25, 25); 
color c2 = color(25, 255, 200); 

imgContainer=new ArrayList<PImage>(); 
for (int i=0; i<n; i++) { 
PImage pimg=loadImage(""); 
pimg.resize(STEPX,STEPY); 
imgContainer.add(pimg); 
} 

noLoop(); //Driven by redraw 
noStroke(); 
} 

void draw() { 
background(250, 250, 250); 
if (newDesign==false) { 
return; 
} 

pic.loadPixels(); 

for (int y = 0; y < height; y+=STEPY) { 
for (int x = 0; x < width; x+=STEPX) { 
// Get the color stored in the pixel 
int index=y*width+x; 
color pixelValue = pic.pixels[index]; 
// Determine the brightness of the pixel 
float pixelBrightness = brightness(pixelValue); 

float imgPicked=map(pixelBrightness,0,255, 0, n); 
println("DEBUGGING check n="+n+" map returns "+imgPicked); 
image(imgContainer.get((int)imgPicked), x, y); 
} 
} 
} 

void mouseReleased() { 
newDesign=!newDesign; 
redraw(); 
} 
+0

你有没有想过这个想法? –

+0

是的,我做了,但我放弃了这个项目,所以我忘了我是怎么做到的:\ – daddydean

回答

0

您可以使用Filethe Java API。它包含列出目录中所有文件(和文件夹)以及获取上次修改时间的功能。

你也应该开始小一点。从基本草图开始,只需打印出最近的文件夹。然后在此基础上构建。如果卡住了,你可以发帖MCVE。还要确保你的代码格式正确,因为你发布的代码很难阅读。祝你好运。

相关问题