Mediamanager:getPicture: Difference between revisions

From GiderosMobile
first attempt at creating methods for media plugin
 
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
<languages />
'''Available since:''' Gideros 2016.1<br/>
'''<translate>Available since</translate>:''' Gideros 2016.1<br/>
'''Class:''' [[Media]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Media|Media]]<br/>


=== <translate>Description</translate> ===
=== Description ===
Allows user to select picture from gallery.
Allows user to select picture from gallery.
<source lang="lua">
<syntaxhighlight lang="lua">
(string) = mediamanager:getPicture()
(string) = mediamanager:getPicture()
</source>
</syntaxhighlight>


=== <translate>Return values</translate> ===
'''ANDROID SDK 29+ HAS SOME BREAKING CHANGES, THIS FUNCTION WILL NOT WORK AS EXPECTED :-('''
'''<translate>Returns</translate>''' (string) <translate>path to the picture</translate><br/>


<!-- {{Media}} -->
=== Return values ===
'''Returns''' (string) path to the picture<br/>
 
=== Example ===
<syntaxhighlight lang="lua">
local alertdialog = AlertDialog.new("ERROR", "TILE MUST BE 128 PIXELS\n", "OK")
btnloadtile:addEventListener("click", function() -- load external tile
local function mediareceive(e)
external_tile_bmp = Bitmap.new(Texture.new(e.path))
local w, h = external_tile_bmp:getWidth(), external_tile_bmp:getHeight()
if w == h and w <= 128 then
g_tilesize = w
scenemanager:changeScene("tile", 0.5, transitions[21], easing.outBack)
else
alertdialog:show()
end
mediamanager:removeEventListener(Event.MEDIA_RECEIVE, mediareceive)
end
mediamanager:getPicture() -- opens windows/android file explorer
mediamanager:addEventListener(Event.MEDIA_RECEIVE, mediareceive)
end)
</syntaxhighlight>
 
=== See also ===
For mobile: '''[[Share:import]]'''
 
{{Media}}

Latest revision as of 20:19, 20 February 2025

Available since: Gideros 2016.1
Class: Media

Description

Allows user to select picture from gallery.

(string) = mediamanager:getPicture()
ANDROID SDK 29+ HAS SOME BREAKING CHANGES, THIS FUNCTION WILL NOT WORK AS EXPECTED :-(

Return values

Returns (string) path to the picture

Example

local alertdialog = AlertDialog.new("ERROR", "TILE MUST BE 128 PIXELS\n", "OK")
btnloadtile:addEventListener("click", function() -- load external tile
	local function mediareceive(e)
		external_tile_bmp = Bitmap.new(Texture.new(e.path))
		local w, h = external_tile_bmp:getWidth(), external_tile_bmp:getHeight()
		if w == h and w <= 128 then
			g_tilesize = w
			scenemanager:changeScene("tile", 0.5, transitions[21], easing.outBack)
		else
			alertdialog:show()
		end
		mediamanager:removeEventListener(Event.MEDIA_RECEIVE, mediareceive)
	end
	mediamanager:getPicture() -- opens windows/android file explorer
	mediamanager:addEventListener(Event.MEDIA_RECEIVE, mediareceive)
end)

See also

For mobile: Share:import