请指导我为iphone写一个代码,我想显示浏览图像的路径以及显示该图像?
答案 0 :(得分:2)
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.kitco.com/images/live/silverw.gif"]];
if([imageData length] == 0){
/*NSString *imagePath = [[NSString alloc] initWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],@"no_image.png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
[item setObject:image forKey:@"itemImage"];
[imagePath release];
[image release];*/
}
else {
UIImage *image = [[UIImage alloc] initWithData:imageData];
mChartImageView.frame = CGRectMake(0,0, 600, 300);
myScrollView.contentSize = mChartImageView.frame.size;
[myScrollView setMinimumZoomScale:-1.0];
[myScrollView setMaximumZoomScale:4.0];
[myScrollView setScrollEnabled:YES];
[myScrollView setContentSize:CGSizeMake(mChartImageView.frame.size.width, mChartImageView.frame.size.height)];
mChartImageView.image = image;
[image release];
}
[pool release];