I used the codes below to load image
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"file://home/%@", filename]];
NSImage *image = [[[NSImage alloc] initWithContentsOfURL:url] autorelease];
but I found that if there is a space in the filename, such as
@”a b.jpg”
image returns 0x0
Welcome any comment
When creating URLs pointing to file system paths, one should use
+fileURLWithPath:or-initFileURLWithPath:. Replace:with:
And, in general, one should use
-[NSString stringByAppendingPathComponent]when composing strings that represent paths. This method takes care of placing a solidus/when appropriate: