开发者

Loading Image from SQL Server DB Image Field into UIImageView

We have images stored in our SQL Server db in an image type field. Im just wanting to know how I go about getting them into a UIImageView in my iPad app. My iPad app talks to the SQL Server over an OData service provider so the image field comes across as type NSData so I tried the following code already:

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

Where "[currentEntityImage getEntityImageData]" is the NSData field converted from the image field. 开发者_运维百科The problem is I can never get anything to display in the UIImageView.

Here is the corresponding code I use in our .net application that shows the image correctly:

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)

This works fine and shows the image correctly (i am accessing the same data on both platforms).

Any ideas on what im missing in my obj-c code? Ive been pulling my hair out all morning on this.

Thanks in advance


maybe the data returned from OData is encoded Base64. Try decoding it with http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html

Hope it helps


Try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜