截取屏幕(考虑分辨率适配)
来源:互联网 发布:装修设计实用软件 编辑:程序博客网 时间:2024/06/16 07:28
1.截取屏幕时取图片实际大小
function MatchWinDialog:screenshotShareToWX() local winSize = cc.Director:getInstance():getWinSize() local bg = gt.seekNodeByName(self.rootNode, "Image_bg") local layerSize = cc.size(985, 535) local dx = winSize.width/2 - 491 local dy = winSize.height/2 - 227 local width, height = layerSize.width, layerSize.height local screenshot = cc.RenderTexture:create(winSize.width, winSize.height) screenshot:begin() self.rootNode:visit() screenshot:endToLua() local spShot = cc.RenderTexture:create(width, height) local tempSp = cc.Sprite:createWithTexture(screenshot:getSprite():getTexture(), cc.rect(dx, dy, width, height)) tempSp:setAnchorPoint(0, 0) tempSp:setPosition(0, 0) tempSp:setFlippedY(true) spShot:begin() tempSp:visit() spShot:endToLua() local screenshotFileName = string.format("wx-%s.jpg", os.date("%Y-%m-%d_%H:%M:%S", os.time())) spShot:saveToFile(screenshotFileName, cc.IMAGE_FORMAT_JPEG, false) self.shareImgFilePath = cc.FileUtils:getInstance():getWritablePath() .. screenshotFileName self.scheduleHandler = gt.scheduler:scheduleScriptFunc(handler(self, self.update), 0, false)end2.考虑左下脚,和大小
function MatchWinDialog:screenshotShareToWX() local winSize = cc.Director:getInstance():getWinSize() local bg = gt.seekNodeByName(self.rootNode, "Image_bg") local layerSize = bg:getContentSize() local pos = bg:getParent():convertToWorldSpace(cc.p(bg:getPositionX(), bg:getPositionY())) --获取成世界坐标就行了 local dx = pos.x - layerSize.width/2 local dy = pos.y - layerSize.height/2 local width, height = layerSize.width, layerSize.height local screenshot = cc.RenderTexture:create(winSize.width, winSize.height) screenshot:begin() self.rootNode:visit() screenshot:endToLua() local spShot = cc.RenderTexture:create(width, height) local tempSp = cc.Sprite:createWithTexture(screenshot:getSprite():getTexture(), cc.rect(dx, dy, width, height)) tempSp:setAnchorPoint(0, 0) tempSp:setPosition(0, 0) tempSp:setFlippedY(true) spShot:begin() tempSp:visit() spShot:endToLua() local screenshotFileName = string.format("wx-%s.jpg", os.date("%Y-%m-%d_%H:%M:%S", os.time())) spShot:saveToFile(screenshotFileName, cc.IMAGE_FORMAT_JPEG, false) self.shareImgFilePath = cc.FileUtils:getInstance():getWritablePath() .. screenshotFileName self.scheduleHandler = gt.scheduler:scheduleScriptFunc(handler(self, self.update), 0, false)end
不断更新检测图片是否存在
function MatchWinDialog:update() if self.shareImgFilePath and cc.FileUtils:getInstance():isFileExist(self.shareImgFilePath) then gt.scheduler:unscheduleScriptEntry(self.scheduleHandler) local shareBtn = gt.seekNodeByName(self.rootNode, "Button_share") shareBtn:setEnabled(true) local platform = gt.SharePlatform.WechatSession if Tools.checkVersion("1.9.0") then platform = gt.SharePlatform.WechatTimeline end gt.shareImage(self.shareImgFilePath, platform) self.shareImgFilePath = nil endend
阅读全文
0 0
- 截取屏幕(考虑分辨率适配)
- 多分辨率屏幕适配
- android分辨率屏幕适配
- 适配不同分辨率屏幕
- Android屏幕适配(分辨率适配)
- android分辨率(屏幕适配)
- 屏幕的分辨率适配问题
- android分辨率(屏幕适配)
- 文字适配不同分辨率屏幕
- android屏幕的多分辨率适配
- iPhone屏幕尺寸、分辨率及适配
- iPhone屏幕尺寸、分辨率及适配
- Android分辨率和屏幕适配经验
- iPhone屏幕尺寸、分辨率及适配
- iPhone屏幕尺寸、分辨率及适配
- iPhone屏幕尺寸、分辨率及适配
- iPhone屏幕尺寸、分辨率及适配
- iPhone屏幕尺寸、分辨率及适配
- 智慧园区参观纪要
- 快速排序法
- hdoj 1800 (Flying to the Mars)
- MySQL关于查询条件中:字符串类型的值忽略英文字母的大小写以及字符串尾部包含空格的问题
- css3样式效果
- 截取屏幕(考虑分辨率适配)
- java验证码工具类(自己编写的,仅供参考)
- bootstrap-table 中columns中editable type为select默认使用本列数据
- 【Linux】命令
- python 安装PyV8 和 lxml
- Apache shiro集群实现 (一) shiro入门介绍
- hdoj 1846
- 编写自己的javascript框架
- 面试题28:字符串的排列