Difference between revisions of "Share.share"
From GiderosMobile
| m (Text replacement - "</source>" to "</syntaxhighlight>") | |||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| __NOTOC__ | __NOTOC__ | ||
| − | + | '''Available since:''' Gideros 2020.7<br/> | |
| − | ''' | + | '''Class:''' [[Share]]<br/> | 
| − | ''' | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | === Description === | |
| + | Shares a piece of data with an external app. | ||
| <syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
| − | + | (bool) = Share.share(mimeType,data) | |
| </syntaxhighlight> | </syntaxhighlight> | ||
| − | ===  | + | This invokes the platform default sharing dialog, allowing to save, print, send, share, etc. | 
| − | '''mimeType''': (string)  | + | |
| − | '''data''': (string) < | + | Currently supported MIME types: | 
| + | * '''"text/*"''' | ||
| + | * '''"image/png"''' | ||
| + | * '''"image/jpeg"''' | ||
| + | |||
| + | === Parameters === | ||
| + | '''mimeType''': (string) the MIME type of the data<br/> | ||
| + | '''data''': (string) the data itself<br/> | ||
| + | |||
| + | === Return values === | ||
| + | '''Returns''' (boolean) ''true'' if data can be shared<br/> | ||
| + | |||
| + | === Examples === | ||
| + | '''Image from file''' | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | require "Share" | ||
| + | |||
| + | local share = Share.new() | ||
| + | |||
| + | local img = io.open("gfx/cat.jpg") | ||
| + | local rimg = img:read("*all") | ||
| + | |||
| + | share.share("image/jpeg", rimg) -- MIME type, data | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | '''Using a Buffer (faster than IO)''' | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | local share = require "Share" | ||
| + | |||
| + | local tex = Texture.new("gfx/cat.jpg") | ||
| + | local bmp = Bitmap.new(tex) | ||
| + | local rt = RenderTarget.new(tex:getWidth(), tex:getHeight()) | ||
| + | rt:draw(bmp) | ||
| + | local buff = Buffer.new("buffer.jpg") -- create a buffer | ||
| + | rt:save("|B|buffer.jpg") -- write to the buffer | ||
| + | |||
| + | local bdata = buff:get() | ||
| + | |||
| + | share.share("image/jpeg", bdata) -- share buffer data | ||
| + | </syntaxhighlight> | ||
| {{Share}} | {{Share}} | ||
Latest revision as of 20:22, 20 February 2025
Available since: Gideros 2020.7
Class: Share
Description
Shares a piece of data with an external app.
(bool) = Share.share(mimeType,data)
This invokes the platform default sharing dialog, allowing to save, print, send, share, etc.
Currently supported MIME types:
- "text/*"
- "image/png"
- "image/jpeg"
Parameters
mimeType: (string) the MIME type of the data
data: (string) the data itself
Return values
Returns (boolean) true if data can be shared
Examples
Image from file
require "Share"
local share = Share.new()
local img = io.open("gfx/cat.jpg")
local rimg = img:read("*all")
share.share("image/jpeg", rimg) -- MIME type, data
Using a Buffer (faster than IO)
local share = require "Share"
local tex = Texture.new("gfx/cat.jpg")
local bmp = Bitmap.new(tex)
local rt = RenderTarget.new(tex:getWidth(), tex:getHeight())
rt:draw(bmp)
local buff = Buffer.new("buffer.jpg") -- create a buffer
rt:save("|B|buffer.jpg") -- write to the buffer
local bdata = buff:get()
share.share("image/jpeg", bdata) -- share buffer data
