【问题标题】:Get the most recent folder using PImage (processing)使用 PImage 获取最新的文件夹(处理)
【发布时间】:2017-07-23 17:06:54
【问题描述】:

我试图弄清楚如何挑选出最近创建的文件夹以加载到 PImage 中。我想不出办法。

我有两个草图,一个创建一堆图像,一个加载它们。这是加载它们的一个。

每次运行其他草图时,都会在我的草图数据文件夹中创建一个新文件夹。我需要挑选出最近创建的文件夹并将其加载到我的 PImage 中。看起来像http://imgur.com/a/u1jF0
因此,下一个文件夹的名称将称为 test_segments2,然后是 test_segments3……等等。

代码:

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

boolean newDesign = false;
PImage pic;

ArrayList<PImage> imgContainer;
int n = 1;

void setup() {
    size(800, 800, P2D);
    colorMode(RGB, 255);
    background(250, 250, 250);
    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>();
    PImage pimg1 = loadImage("THIS IS WHERE I NEED THE PATH OF MOST RECENT FOLDER CREATED TO GO");
    pimg1.resize(50, 50);
    noLoop();
    noStroke();
}

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

    pic.loadPixels();

    for (int y = 0; y < height; y += 40) {
        for (int x = 0; x < width; x += 40) {
            int index = y * width + x;
            color pixelValue = pic.pixels[index];
            color rgb = pixelValue;
            int r = (rgb >> 16) & 0xFF; // Faster way of getting red(argb)
            int g = (rgb >> 8) & 0xFF; // Faster way of getting green(argb)
            int b = rgb & 0xFF;

            // How far is the current color from white
            float dista = dist(r, g, b, 255, 255, 255);

            // 50 is a threshold value allowing close to white being
            // identified as white
            // This value needs to be adjusted based on your actual
            // background color
            // Next block is processed only if the pixel not white
            if (dista > 30) {
                float pixelBrightness = brightness(pixelValue);
                float imgPicked = constrain(pixelBrightness / thresh, 0, n - 1);
                image(imgContainer.get((int) imgPicked), x, y);
            }
        }
    }
}

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

【问题讨论】:

    标签: java image processing


    【解决方案1】:

    您可以使用the Java API 中的File 类。例如,它具有让您列出目录中所有文件的功能。您可以使用它按名称对它们进行排序,然后获取最新的。或者您甚至可以使用这个类来获取有关文件的元数据并找到最近修改的文件。

    【讨论】:

    • 好酷。在列出的所有文件类型中,哪一种效果最好?我看到文件数据源、文件过滤器、文件名过滤器...?
    • @guyintightpants 我会从 File 类开始。
    • 我只是不确定如何获取使用文件类创建的最新文件,老实说,我找不到我需要的东西......功能太多了
    • @guyintightpants 首先,找到为您提供目录中所有文件列表的函数。谷歌搜索“目录中的 Java 列表文件”之类的内容将是一个不错的起点。
    • 所以我得到了帮助,我的第一个草图创建了目录路径:pastebin.com/VNU78Cks 看起来像:imgur.com/a/MeQxG 但我不确定如何将这些加载到此草图的 Pimage 中。跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    • 2023-02-22
    • 2017-05-31
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多