以下是使用C语言在6818开发板上浏览用户指定目录下的图片并过滤非jpg格式文件的示例代码:

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

int isImageFile(const char *filename) {
    char *extension = strrchr(filename, '.');
    if (extension != NULL && strcmp(extension, ".jpg") == 0) {
        return 1;
    }
    return 0;
}

void browseDirectory(const char *dirname) {
    DIR *dir;
    struct dirent *entry;

    dir = opendir(dirname);
    if (dir == NULL) {
        printf("Error opening directory: %s\n", dirname);
        return;
    }

    while ((entry = readdir(dir)) != NULL) {
        if (entry->d_type == DT_REG) {
            char filepath[256];
            strcpy(filepath, dirname);
            strcat(filepath, "/");
            strcat(filepath, entry->d_name);

            if (isImageFile(entry->d_name)) {
                printf("Image file found: %s\n", filepath);
                // 在此处进行图片处理操作
            }
        }
    }

    closedir(dir);
}

int main() {
    char dirname[256];

    printf("Enter directory path: ");
    scanf("%s", dirname);

    printf("Browsing images in directory: %s\n", dirname);
    browseDirectory(dirname);

    return 0;
}

请注意,上述代码仅列出了找到的图片文件的路径。如果您希望对图片进行进一步的处理操作,可以在browseDirectory函数的相应位置添加您的代码

用c语言实现在6818开发板上浏览用户指定的目录下的图片支持目录内文件过滤一个目录内有多种类型的文件过滤掉非jpg格式的文件

原文地址: http://www.cveoy.top/t/topic/iGiC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录