Sprite* spr1 = Sprite::create("spr1.png");
spr1->retain();//在3.0此处必须写上这个
auto render = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888);
render->retain();
render->beginWithClear(0, 0, 0, 255);
spr1->visit();
render->end();
Director::getInstance()->getRenderer()->render();//在3.0此处必须写上这个,否则newImage整张图片都为黑色,或者在下一帧获取
char jpg2[20];
sprintf(jpg2, "image-%d.jpg", 123);
std::string fullpath1 = FileUtils::getInstance()->getWritablePath() + jpg2;
Image* image1 = render->newImage();
image1->saveToFile(fullpath1, true); //设置保存目录和文件名
image1->release();
关于cocos2dx RenderTexture的newImage为空
最新推荐文章于 2021-04-25 16:21:07 发布