Reputation: 2880
I am getting a byte array(I reckon) in NSMutableArray's
object.The NSMutableArray
i get is from Xml
parsing from a service URL..Now I need to convert that byte array to UIImage
..Gone through google and found to convert to NSData
and then UIImage
but couldn't understand how..? How can I do it ?
My array looks like this :
(
{
Name = "John";
Image = "/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJS
kcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gODAK/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXF
BYWGh0lHxobIxwWFiAsICMmJykqKRkfLTAtKDAlKCko/9sAQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo/8AAEQgEKwZAAwEiAAIRAQMRAf/........
//big byte array
}
)
First of all I need to clear whether it is a byte array ?How can I extract image from this ?
Upvotes: 1
Views: 3580
Reputation: 79023
Your data is organized like this:
NSArray
or NSMutableArray
(as you write).NSDictionary
instance.So the get the image, you need to go this path:
NSMutableArray* array = ... // from XML
NSDictionary* dict = [array objectAtIndex: 0];
NSString* dataString = [dict objectForKey: @"Image"];
NSData* imageData = [dataString base64DecodedData];
UIImage* image = [UIImage imageWithData: imageData];
Note that the Base64 decoding is not part of iOS. But there are many implementations on the net for decoding a string into data. Just google it.
A Base64 implementation that looks good and simple can be found on GitHub.
Upvotes: 5