2012-05-10 56 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

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

相關問題