objective-c – [[NSBundle mainBundle] bundlePath]中的图像计数

objective-c – [[NSBundle mainBundle] bundlePath]中的图像计数,第1张

概述如何在[[NSBundle mainBundle] bundlePath]的特定文件夹中找到图像数量…. 例如:/ Users / Nag / Library / Application Support / iPhone Simulator / 4.2 / Applications / 4409487C-1035-4329-B38A-B6F21E00FC63 / MakeUp_IPhone.app 如何在[[NSBundle mainBundle] bundlePath]的特定文件夹中找到图像数量….

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

解决方法 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

检查以上链接.他们可能会为您的问题提供解决方案.
这是给你的代码:

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

要从特定文件夹获取图像,请参阅: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        }    }

看到这个:

// create the route of localdocumentsFolderNSArray *filePaths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);//first use the local documents folderNsstring *docsPath = [Nsstring stringWithFormat:@"%@/documents",NSHomeDirectory()];//then use its bundle,indicating its pathNsstring *bundleRoot = [[NSBundle bundleWithPath:docsPath] bundlePath];//then get its contentNSArray *dirContents = [[NSfileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];// this counts the total of jpg images contained in the local document folder of the appNSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[nspredicate predicateWithFormat:@"self ENDSWITH '.JPG'"]];// in console tell me how many jpg do I haveNSLog(@"numero de fotos en total: %i",[onlyJPGs count]);// ---------------
总结

以上是内存溢出为你收集整理的objective-c – [[NSBundle mainBundle] bundlePath]中的图像计数全部内容,希望文章能够帮你解决objective-c – [[NSBundle mainBundle] bundlePath]中的图像计数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1034243.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存