从 NSURL 加载图片

只是单纯地为了备忘


我有一个图片的路径,名叫 filePath 。 它是一个 NSURL 类型的对象,里面存有一张图片的路径。
遂用以下方法获取此图片并显示在一个 UIImageView 里面:

    NSData *data = [[NSData alloc] initWithContentsOfURL:filePath];
    UIImage *image = [UIImage imageWithData:data];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imgView.frame = CGRectMake(20, 20, 200, 200);
    [self.view addSubview:imageView];
posted @ 2015-04-29 11:44  verain  阅读(285)  评论(0编辑  收藏  举报