版本:1.7.0-beta2
平台:mac
let dirpath = jsb.fileUtils.getWritablePath() + 'ScreenShoot/'; if( !jsb.fileUtils.isDirectoryExist(dirpath)){ jsb.fileUtils.createDirectory(dirpath); } let name = 'ScreenShoot-' + (new Date()).valueOf() + '.png'; let filepath = dirpath + name; let size = cc.winSize; let rt = cc.RenderTexture.create(size.width, size.height); cc.director.getScene()._sgNode.addChild(rt); rt.setVisible(false); rt.begin(); cc.director.getScene()._sgNode.visit(); rt.end(); rt.saveToFile('ScreenShoot/' + name, cc.IMAGE_FORMAT_PNG, true, function() { cc.log('save succ'); rt.removeFromParent(); if (func) { func(filepath); } }); return filepath;
我使用上面这段代码在原生平台上截屏,但是会报错:
ERROR: TypeError: rt_1.saveToFile is not a function. (In ‘rt_1.saveToFile’, ‘rt_1.saveToFile’ is undefined), location: src/project.dev.js:24396:24
STACK:
captureScreenshot@src/project.dev.js:24396:24
onClickCap@src/project.dev.js:9765:33
emit@src/jsb_polyfill.js:9016:24
emitEvents@src/jsb_polyfill.js:9001:25
_onTouchEnded@src/jsb_polyfill.js:8610:49
invoke@src/jsb_polyfill.js:13877:28
_doDispatchEvent@src/jsb_polyfill.js:13922:109
dispatchEvent@src/jsb_polyfill.js:14039:25
_touchEndHandler@src/jsb_polyfill.js:5495:27
jsb: ERROR: File /Users/game/wind/game-client/build/jsb-default/frameworks/cocos2d-x/cocos/scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp: Line: 465, Function: invokeJSTouchOneByOneCallback
invokeJSTouchOneByOneCallback call function failed!
手动顶一下@jare
谢谢反馈,这个在1.6.2是手动绑定的函数,1.7中漏了此函数。稍后修复。
cc.IMAGE_FORMAT_PNG是哪里定义的?我这里是undefined。查了一下1.6,也没有这个枚举定义。
creator.d.ts里面
/** Image formats */
export enum ImageFormat {
JPG = 0,
PNG = 0,
TIFF = 0,
WEBP = 0,
PVR = 0,
ETC = 0,
S3TC = 0,
ATITC = 0,
TGA = 0,
RAWDATA = 0,
UNKNOWN = 0,
getImageFormatByData = 0,
}
那应该是cc.ImageFormat.PNG吧,你写的是cc.IMAGE_FORMAT_PNG.

你好,用saveToFile会让截屏的图片保存在手机上吗?
