我需要使用我的cordova iOs项目中的WWW/Images
文件夹中存在的图像。我正在使用cordova-2.3.0和iOs 6版本。为www/Images文件夹中的图像创建UiImage
我试图通过下面的代码得到图像,但它不适用于WWW/Images
文件夹中的图像,它对资源文件夹中存在的图像正常工作。
UIImage *image = [UIImage imageNamed:@"Car_Main.png"];
如何访问存在于WWW/Images
文件夹中的图像。
我需要使用我的cordova iOs项目中的WWW/Images
文件夹中存在的图像。我正在使用cordova-2.3.0和iOs 6版本。为www/Images文件夹中的图像创建UiImage
我试图通过下面的代码得到图像,但它不适用于WWW/Images
文件夹中的图像,它对资源文件夹中存在的图像正常工作。
UIImage *image = [UIImage imageNamed:@"Car_Main.png"];
如何访问存在于WWW/Images
文件夹中的图像。
我真的不明白,你的WWW/Images文件夹在哪里。如果在应用程序目录中 - 试试这个代码。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/WWW/Images/Car_Main.png"];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath];
如果在项目中 - 也许你忘了添加图像到目标资源?
// Save from documents
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/WWW/Images/Car_Main.png.png"];
BOOL Done = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!Done) {
NSLog(@"Error creating file %@", path);
} else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(yourImage)];
[myFileHandle closeFile];
}
// Get from documents
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];