2011-06-08 45 views
0

我們在圖像類型字段中存儲了存儲在我們的SQL Server數據庫中的圖像。我只是想知道如何讓他們進入我的iPad應用程序的UIImageView。我的iPad應用程序會談到SQL Server通過OData服務提供商所以像場遇到類型NSData的,所以我嘗試下面的代碼已經:將圖像從SQL Server數據庫圖像字段加載到UIImageView中

UIImage *currentImage = [[UIImage alloc] initWithData:[currentEntityImage getEntityImageData]]; 
[myImageView setImage:currentImage]; 

其中「[currentEntityImage getEntityImageData]」是NSData的字段從轉換圖像領域。問題是我永遠不能得到任何東西在UIImageView中顯示。

下面是相應的代碼,我在我們的.NET應用程序中使用正確顯示圖像:

Dim EntImage As EntityImage = CType(e.Entities.Item(0), EntityImage) 
Dim ms As New System.IO.MemoryStream(EntImage.EntityImage) 
Me.imgEntityImage.Image = System.Drawing.Image.FromStream(ms) 

這工作正常,並正確顯示圖像(我訪問這兩個平臺上相同的數據)。

關於在我obj-c代碼中缺少什麼的任何想法?我整個早上都把頭髮拉出來。

在此先感謝

回答

0

試試這個

NSData *imageData =[NSData dataWithData:[currentEntityImage getEntityImageData]]; 
UIImage *animalImage = [[UIImage alloc] initWithData:imageData]; 
[myImageView setImage:animalImage]; 
+0

沒有什麼區別。不是第一行代碼冗餘,因爲[currentEntityImage getEntityImageData]已經是NSData類型 – IPadHackAndSlash 2011-06-08 05:03:44

+0

對不起,把斷點和檢查currentImage對象的值。 – 2011-06-08 05:09:50

相關問題