2011-06-08 48 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

相关问题