如何使用Corona SDK邮寄截屏图像 [英] How to mail a screen captured image using corona SDK

查看:74
本文介绍了如何使用Corona SDK邮寄截屏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是corona SDK的新手,但是我设法使用以下代码捕获了我的应用场景:

I am new to corona SDK, but I've managed to capture my app scene using the following code:

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

这很完美。

现在,我需要通过电子邮件将捕获的图像(具有特定名称,例如: screen_1.png )发送给我的朋友。我使用了撰写电子邮件和SMS 作为参考,但我不明白如何在邮件选项的附件字段中添加此保存的图像。

Now I need to send the captured image(with a specific name, say: screen_1.png) to my friend via email. I've used Composing E-mail and SMS for refference, but I fail to understand how I can add this saved image in the attachment field of mail options.

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

Please give me a proper solution that how can I attach and send the above saved image via email.

推荐答案

display.captureBounds 可以将整个屏幕保存到目录中。但是它通常随着最后索引的增加来保存文件。因此,可能难以正确阅读它们。所以我更喜欢 display.save 。但这不是一条直路。

display.captureBounds is good for saving the whole screen to the directory. But it usually saves the file with increase in last index. So it may be difficult to read them correctly. So I prefer display.save. But it is not a straight way.

为此,您必须:


  • 首先创建 localgroup

  • 然后添加屏幕对象到该组。

  • 返回显示组

  • 使用 display.save 保存显示的整个组。

  • 创建邮件选项并从 baseDirectory添加附件图像

  • 呼叫邮件弹出窗口

  • First create a localgroup.
  • Then add the screen objects to that group.
  • Return the display group
  • Use display.save to save the entire group displayed.
  • Create mail option and add attachment image from baseDirectory
  • Call mail Popup

我在这里提供示例:

-- 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)

...

继续编码.....:)

Keep coding........ :)

这篇关于如何使用Corona SDK邮寄截屏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆