开发者

How to display a image downloaded from URL in iPhone?

I am downloading a image from the url and saving it. When i try to display the same image in UI using ImageView I am not able to do it. So please suggest what changes I need to be done in the following code.

Thank you.

{

NSLog(@"Downloading...");

    UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.objectgraph.com/images/og_logo.png"]]];

    NSLog(@"%f,%f",image.size.width,image.size.height);

    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSLog(@"%@",docDir);

    NSLog(@"saving png::::%@", docDir);
    NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
    NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
    [data1 writeToFile:pngFilePath atomica开发者_如何学JAVAlly:YES];

 NSString *sss = [docDir stringByAppendingString:@"/test.png"];

    imageView1.image = [UIImage imageNamed:sss];

    NSLog(@"------%@",sss);

[image release];

}


UIImage *theUIimage = [UIImage imageNamed:sss];
image = [[UIImageView alloc] initWithImage:theUIimage];
[imageView1 addSubview:image];


How is your imageView initalized? Make sure to also specify the imageView.frame.

e.G.:

CGRect frame = CGRectMake(xPositionInView,yPositionInView,
                          image.size.width,image.size.height); 
imageView.frame = frame;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜