Unable to read Images from xcode project for example. drag and drop one image to xcode project, then read using following code.
__weak NSString *strTemp = [NSString stringWithFormat:@"%@/s_%@",[[NSBundle mainBundle] resourcePath],[[self.arr_gallery objectAtIndex:i]valueForKey:@"filename_larger"]];
strTemp = [strTemp substringToIndex:[strTemp length]-3];
strTemp = [NSString stringWithFormat:@"%@png",strTemp];
// NSString *strTemp = [[NSString alloc] initWithFormat:@"%@/s_BGP001@2x.png",[[NSBundle mainBundle] resourcePath]];
UIImage *image;
image = [[UIImage alloc] initWithContentsOfFile:strTemp];
img.image = image;
strTemp = nil;
Write following code.
NSString *newStrTemp = [strTemp stringByReplacingOccurrencesOfString:@"jpg" withString:@"png"];
Instead of this one.
strTemp = [strTemp substringToIndex:[strTemp length]-3];
strTemp = [NSString stringWithFormat:@"%@png",strTemp];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.