2010-10-13 75 views
4

我在iphone中顯示圖像時遇到問題。我使用下面的代碼,但它只適用於.png文件。如何在iPhone中顯示類型.jpeg或.gif或.tiff的圖像sdk

 UIImageView* imageView=[[UIImageView alloc] initWithFrame:CGRectMake(6,10, 80, 80)]; 
     imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:customerListObject.customerImage]]]; 
     [myView addSubview:imageView]; 
     [imageView release]; 

我無法顯示其他類型的圖像文件,請建議我解決方案。

謝謝 馬丹磨憨

使用該
+0

你試過用本地圖像和[UIImage imageNamed:@「」]? – Vinzius 2010-10-13 12:30:54

+0

它與它一起工作,但我需要與其他類型顯示 – 2010-10-13 13:46:05

+0

你確認你對[NSData dataWithContentsOfURL:]和[UIImage imageWithData:]的調用不返回零嗎?也就是說,你是否從URL獲取數據,並且數據是否成功地轉化爲UIImage? – Ryan 2010-12-03 17:31:36

回答

1

嘗試:

imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"imagename" ofType:@"png"]]; 

然後用您的文件名稱和類型替換imagename和PNG。

+0

我從解析器中獲取圖像URL,我如何使用NSBundle – 2010-10-13 13:44:27

相關問題