【发布时间】:2015-02-27 05:50:56
【问题描述】:
首先我将 URL 中的图片保存在文档目录中:
NSURL *imageURL = [NSURL URLWithString:userImage];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"image name.png"];
[UIImagePNGRepresentation(image) writeToFile:savedImagePath atomically:YES];
然后我想在 cpp 中检索这张图片作为 Sprite:
std::string writablePath2 = CCFileUtils::getInstance()->getWritablePath();
writablePath2.append("your saved image.png");
Rect rect2 = Rect(visibleSize.width/2 - 200, visibleSize.height/2 -200 , 500, 500 );
Sprite *screen_shot = Sprite::create(writablePath2,rect2);
screen_shot->setPosition(visibleSize.width/2 ,origin.y + visibleSize.height/2 - 100);
this->addChild(screen_shot,2);
但它显示的是黑色精灵。
【问题讨论】:
-
删除rect2,我认为它会工作。likes Sprite *screen_shot = Sprite::create(writablePath2);
标签: uiimage ccsprite cocos2d-x-3.0