将图像从SQL Server数据库图像字段加载到UIImageView中
问题描述:
我们在图像类型字段中存储了存储在我们的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代码中缺少什么的任何想法?我整个早上都把头发拉出来。
在此先感谢
答
试试这个
NSData *imageData =[NSData dataWithData:[currentEntityImage getEntityImageData]];
UIImage *animalImage = [[UIImage alloc] initWithData:imageData];
[myImageView setImage:animalImage];
答
也许从OData的返回的数据进行base64编码。 尝试用http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
解码它希望它可以帮助
没有什么区别。不是第一行代码冗余,因为[currentEntityImage getEntityImageData]已经是NSData类型 – IPadHackAndSlash 2011-06-08 05:03:44
对不起,把断点和检查currentImage对象的值。 – 2011-06-08 05:09:50