将照片库 URL 保存为 NSString,然后返回 URL
我想做的是将 URL 保存到照片库图片之一。然后使用此 URL 在 CCSprite 上设置图像。 这是保存为 NSString 的 URL:
[_currentTarget setObject:[[NSString alloc]initWithString:[[info objectForKey:@"UIImagePickerControllerReferenceURL"]absoluteString]] forKey:@"image1Name"];
然后设置我制作的 Target 对象的属性
NSString *image1PathName = [[listOfUserMadeTargets objectAtIndex:num]objectForKey:@"image1Name"];
self.normalImage = image1PathName;
这是在制作 CCSprite 时
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" ]];
我遇到的问题是 Target 在那里,但图像不是
我已经做了很多不同的事情没有运气的方法
谢谢你的帮助
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一篇文章(并且答案)我制作的内容向您展示了如何在 CameraRoll 中保存
UIImage
的NSURL
,并在稍后使用它来使用UIImagePickerController< /代码>。此示例代码还应该帮助您了解如何访问图像。希望有帮助!
This is a post (and answer) I made which shows you how to save the
NSURL
for aUIImage
in the CameraRoll, and use it later to get the image back, using aUIImagePickerController
. This sample code should also help you in how to access the image. Hope that Helps!