-1

I want to dispay an online image in imageview and save it to database following code display only a particular image. I can also save that image to database.

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://tvaraj.files.wordpress.com/2012/03/sachin-tendulkar-when-young.jpg&w=231&h=2500&ei=SiKqT9-fKILprQfIudWCAQ&zoom=1"]]];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];   
img.image=[UIImage imageWithData:data1];
NSLog(@"image=%@",img.image);
imageToUse1= img.image;
[image release];

//i want to add this code. this is for 
WebView *Wview=[[WebView alloc]init];
[self.navigationController pushViewController:Wview animated:YES];

My requirement is if I click any image that should display in the imageview.

How is it possible?

4

1 に答える 1

0
  UIImage* myImage = [UIImage imageWithData: 
  [NSData dataWithContentsOfURL: 
  [NSURL URLWithString: @"http://example.com/image.jpg"]]];

また、画像ビューで使用する場合は、次の手順を実行してください。

//画像がインスタンス化されたUIImageViewであると仮定しましょう

  [picture setImage: myImage];
  [myImage release];

画像をデータベースに保存

  NSData *data1 = UIImagePNGRepresentation(myImage, 1.0);   // save this nsdata to ur database.
于 2012-05-10T05:58:22.780 に答える