cocos2d-x截屏功能clippingnode也能使用——白白

cocos2d-x截屏功能clippingnode也能使用——白白,第1张

概述更多精彩分享:http://blog.csdn.net/u010229677 3.1版本: 在Director里面增加一个函数: bool Director::saveScreenshot(const std::string& fileName,const std::function<void(const std::string&)>& callback) { Image::Format fo

更多精彩分享:http://blog.csdn.net/u010229677

3.1版本:

在Director里面增加一个函数:

bool Director::saveScreenshot(const std::string& filename,const std::function<voID(const std::string&)>& callback) {	Image::Format format;  	//进行后缀判断  	if(std::string::npos != filename.find_last_of(".")){  		auto extension = filename.substr(filename.find_last_of("."),filename.length());  		if (!extension.compare(".png")) {  			format = Image::Format::PNG;  		} else if(!extension.compare(".jpg")) {  			format = Image::Format::JPG;  		} else{  			cclOG("cocos2d: the image can only be saved as JPG or PNG format");  			return false;  		}  	} else {  		cclOG("cocos2d: the image can only be saved as JPG or PNG format");  		return false ;  	}  	//获取屏幕尺寸,初始化一个空的渲染纹理对象  	auto renderTexture = RenderTexture::create(getWinSize().wIDth,getWinSize().height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8); //最后一个参数省略的话,对clipPingnode截图是无效的	//清空并开始获取  	renderTexture->beginWithClear(0.0f,0.0f,0.0f);  	//遍历场景节点对象,填充纹理到RenderTexture中  	getRunningScene()->visit();  	//结束获取  	renderTexture->end();  	//保存文件  	renderTexture->savetofile(filename,format);  	//使用schedule在下一帧中调用callback函数  	auto fullPath = fileUtils::getInstance()->getWritablePath() + filename;  	auto scheduleCallback = [&,fullPath,callback](float dt){  		callback(fullPath); 	};  	return true;}

调用的话:
Director::getInstance()->saveScreenshot("sss.png", nullptr);

3.2版本:
#include "base/ccUtils.h"utils::captureScreen([](){log("ok");},"dd.png");
总结

以上是内存溢出为你收集整理的cocos2d-x截屏功能clippingnode也能使用——白白全部内容,希望文章能够帮你解决cocos2d-x截屏功能clippingnode也能使用——白白所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1006363.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存