Ryan Erb
Ryan Erb

Reputation: 838

save a photo library URL as an NSString then back to URL

what i am trying to do is save a URL to one of the photo library pictures. then use this URL to set the image on a CCSprite. this is the URL being saved as a NSString :

[_currentTarget setObject:[[NSString alloc]initWithString:[[info objectForKey:@"UIImagePickerControllerReferenceURL"]absoluteString]] forKey:@"image1Name"];

Then set the a property of a Target object i made

NSString *image1PathName = [[listOfUserMadeTargets objectAtIndex:num]objectForKey:@"image1Name"];
self.normalImage = image1PathName;

this is when the CCSprite is made

Target *target = [[Target alloc] targetThatIsUserMade];

[_targets addObject:target]; // add it to the array

target.position = ccp(spawnX,spawnY);

target.scale = -0.001875 * target.position.y + 1.09375;

[self addChild:target z:1];

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:target.normalImage]]];

[target setTexture:[[CCTextureCache sharedTextureCache] addCGImage:image.CGImage    forKey:@"key" ]];

The problem im having is that the Target is there, but the image is not

I have done this many different ways with no luck

thank you for any help

Upvotes: 3

Views: 570

Answers (1)

msgambel
msgambel

Reputation: 7340

This is a post (and answer) I made which shows you how to save the NSURL for a UIImage in the CameraRoll, and use it later to get the image back, using a UIImagePickerController. This sample code should also help you in how to access the image. Hope that Helps!

Upvotes: 1

Related Questions