我的 [[NSBundle mainBundle] bundlePath] 中的图像计数

发布于 2024-12-03 06:41:53 字数 246 浏览 0 评论 0原文

如何在特定的我的文件夹中找到 [[NSBundle mainBundle] bundlePath] 中的图像数量...

例如:/Users/Nag/Library/Application Support/iPhone Simulator/4.2/Applications/4409487C-1035-4329-B38A-B6F21E00FC63/MakeUp_IPhone.app/"MyFolder"

How can you find count of images in [[NSBundle mainBundle] bundlePath] at particular my folder....

Eg: /Users/Nag/Library/Application Support/iPhone Simulator/4.2/Applications/4409487C-1035-4329-B38A-B6F21E00FC63/MakeUp_IPhone.app/"MyFolder"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不气馁 2024-12-10 06:41:53

http://www.ericd.net/ 2009/06/iphone-getting-images-from-your-bundle.html

http://www.cocoabuilder.com/archive/cocoa/239638-number-of-images-in-main-bundle-folder-iphone.html cocoabuilder.com/archive/cocoa/239638-number-of-images-in-main-bundle-folder-iphone.html

检查上述链接。他们可能会为您的问题提供解决方案。
以下是适合您的代码:

    totalCount = 0;
    NSArray *d = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];
    for(NSString *s in d)
    {
       if([[s lastPathComponent] hasPrefix:@"image_"]){
       totalCount++;
       }
    }

要从特定文件夹获取图像,请参阅:计数图像< /a>

    NSEnumerator *iter = [[NSFileManager defaultManager] directoryEnumeratorAtPath:[[NSBundle mainBundle] bundlePath]];
    int count = 0; // number of images
    for (NSString *path in iter) { // iterate through all files in the bundle
         if ([[path pathExtension] isEqualToString:@"png"]) { // test if the extension is "png"
            count++; // increment the number of images
            UIImage *img = [UIImage imageWithContentsOfFile:path];
            // do other things with the image
        }
    }

另请参阅:

// create the route of localDocumentsFolder
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//first use the local documents folder
NSString *docsPath = [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];
//then use its bundle, indicating its path
NSString *bundleRoot = [[NSBundle bundleWithPath:docsPath] bundlePath];
//then get its content
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
// this counts the total of jpg images contained in the local document folder of the app
NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.JPG'"]];
// in console tell me how many jpg do I have
NSLog(@"numero de fotos en total: %i", [onlyJPGs count]);
// ---------------

http://www.ericd.net/2009/06/iphone-getting-images-from-your-bundle.html

http://www.cocoabuilder.com/archive/cocoa/239638-number-of-images-in-main-bundle-folder-iphone.html

Check the above links. They may provide a solution to your problem.
Here is the code for you:

    totalCount = 0;
    NSArray *d = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];
    for(NSString *s in d)
    {
       if([[s lastPathComponent] hasPrefix:@"image_"]){
       totalCount++;
       }
    }

For getting images froma a paticular folder, see this: count no.of images

    NSEnumerator *iter = [[NSFileManager defaultManager] directoryEnumeratorAtPath:[[NSBundle mainBundle] bundlePath]];
    int count = 0; // number of images
    for (NSString *path in iter) { // iterate through all files in the bundle
         if ([[path pathExtension] isEqualToString:@"png"]) { // test if the extension is "png"
            count++; // increment the number of images
            UIImage *img = [UIImage imageWithContentsOfFile:path];
            // do other things with the image
        }
    }

See this also:

// create the route of localDocumentsFolder
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//first use the local documents folder
NSString *docsPath = [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];
//then use its bundle, indicating its path
NSString *bundleRoot = [[NSBundle bundleWithPath:docsPath] bundlePath];
//then get its content
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
// this counts the total of jpg images contained in the local document folder of the app
NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.JPG'"]];
// in console tell me how many jpg do I have
NSLog(@"numero de fotos en total: %i", [onlyJPGs count]);
// ---------------
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文