2012-05-10 36 views
-1

我想在图像视图中显示在线图像并将其保存到数据库 下面的代码仅显示特定图像。我也可以将该图像保存到数据库。将图像从在线显示到iphone的imageview并保存到数据库中

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]; 

我的要求是,如果我点击任何图像,应该在imageview中显示。

这怎么可能?

回答

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. 
+0

我已经试过这个code.this是只有一个image.my的要求是选择一个图像从多个图像 –

+0

您可以使用'for'循环显示来自服务器的多个图像。 – akk

+0

我可以得到任何示例代码 –

相关问题