cocos2dx-lua3.12版本保存图片、截屏显示

cocos2dx-lua3.12版本保存图片、截屏显示,第1张

概述保存图片到本地: --[[ 下面代码的意思是将大图plist文件中的分离出来,并保存到沙盒目录下 ]] local size = cc.Director:getInstance():getVisibleSize() local plistFile = ""   --你的plist路径 local pngFile = ""   --你的大图路径 cc.SpriteFrameCache:getInst

保存图片到本地:

--[[

下面代码的意思是将大图pList文件中的分离出来,并保存到沙盒目录下

]]

local size = cc.Director:getInstance():getVisibleSize()

local pListfile = "" --你的pList路径

local pngfile = "" --你的大图路径

cc.SpriteFrameCache:getInstance():addSpriteFrames(pListfile) --加载图片进内存

local vectormap = cc.fileUtils:getInstance():getValueMapFromfile(pListfile) --读取pList

local frames = vectormap.frames

local writablePath = cc.fileUtils:getInstance():getWritablePath()

print("writablePath is %s",writablePath)

for key,value in pairs(frames) do

local str = key --获得pList内的图片名

local spr = cc.Sprite:createWithSpriteFrame@R_301_6889@(str)

local size = spr:getContentSize()

local render = cc.RenderTexture:create(size.wIDth,size.height)

spr:setposition(cc.p(size.wIDth / 2,size.height / 2))

render:begin()

spr:visit()

render:endTolua()

ender:savetofile(str,cc.IMAGE_FORMAT_PNG) --写到文件

print("save " .. str .. " to ".. writablePath .. str)

end


截屏显示

local size = cc.Director:getInstance():getVisibleSize()

local function afterCaptured(succeed,outputfile)

if succeed then

local outputSprite = cc.Sprite:create(outputfile)

outputSprite:setposition(cc.p(size.wIDth/2,size.height/2))

self:addChild(outputSprite,10)

outputSprite:setScale(0.5)

else

print("Capture screen Failed.")

end

end


local screen = cc.MenuItemFont:create("SCREEN")

screen:setposition(cc.p(size.wIDth-100,size.height-100))

local menu = cc.Menu:create(screen)

menu:setposition(cc.p(0,0))

menu:setAnchorPoint(cc.p(0,0))

self:addChild(menu)

local function menuCallBack(pSender)

cc.utils:captureScreen(afterCaptured,"screen.png")

end

screen:registerScriptTapHandler(menuCallBack)

总结

以上是内存溢出为你收集整理的cocos2dx-lua3.12版本保存图片、截屏显示全部内容,希望文章能够帮你解决cocos2dx-lua3.12版本保存图片、截屏显示所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1081136.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存