gpt4 book ai didi

email - 如何使用 Corona SDK 发送截屏图像

转载 作者:行者123 更新时间:2023-12-02 03:44:48 26 4
gpt4 key购买 nike

我是 corona SDK 的新手,但我已经使用以下代码成功捕获了我的应用场景:

local function captureArea()
local myCaptureImage = display.captureBounds(display.currentStage.contentBounds, true)
myCaptureImage:removeSelf()
myCaptureImage = nil
end
bg:addEventListener("tap",captureArea)

这非常有效。

现在我需要通过电子邮件将捕获的图像(具有特定名称,例如:screen_1.png)发送给我的 friend 。我用过 Composing E-mail and SMS仅供引用,但我不明白如何在邮件选项的 attachment 字段中添加此保存的图像。

请给我一个正确的解决方案,我如何通过电子邮件附加并发送上面保存的图像。

最佳答案

display.captureBounds 适合将整个屏幕保存到目录中。但它通常会在最后一个索引增加的情况下保存文件。所以可能很难正确阅读它们。所以我更喜欢display.save。但这不是一条直路。

为此,您必须:

  • 首先创建一个localgroup
  • 然后将屏幕对象添加到该组。
  • 返回显示组
  • 使用display.save 保存显示的整个组。
  • 创建邮件选项并从 baseDirectory 添加 attachment 图片
  • 调用邮件弹出

我在这里给出一个示例:

-- creating the display group --
local localGroup = display.newGroup()

-- creating display objects and adding it to the group --
local bg = display.newRect(0,0,_w,_h)
bg.x = 160
bg.y = 240
bg:setFillColor(150)
localGroup:insert(bg)

local rect = display.newRect(0,0,50,50)
rect.x = 30+math.random(260)
rect.y = 30+math.random(420)
localGroup:insert(rect)

-- Then do as follows --
local function takePhoto_andSendMail()
-- take screen shot to baseDirectory --
local baseDir = system.DocumentsDirectory
display.save( localGroup, "myScreenshot.jpg", baseDir )

-- Create mail options --
local options =
{
to = { "krishnarajsalim@gmail.com",},
subject = "My Level",
body = "Add this...",
attachment =
{
{ baseDir=system.DocumentsDirectory, filename="myScreenshot.jpg", type="image" },
},
}

-- Send mail --
native.showPopup("mail", options)
end
rect:addEventListener("tap",takePhoto_andSendMail)

这样就可以了...

继续编码......... :)

关于email - 如何使用 Corona SDK 发送截屏图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17752494/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com