Difference between revisions of "Mediamanager:getPicture"

From GiderosMobile
m
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== 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>
  
 
=== Return values ===
 
=== Return values ===
Line 13: Line 13:
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
local alertdialog = AlertDialog.new("ERROR", "TILE MUST BE 128 PIXELS\n", "OK")
 
local alertdialog = AlertDialog.new("ERROR", "TILE MUST BE 128 PIXELS\n", "OK")
 
btnloadtile:addEventListener("click", function() -- load external tile
 
btnloadtile:addEventListener("click", function() -- load external tile
Line 30: Line 30:
 
mediamanager:addEventListener(Event.MEDIA_RECEIVE, mediareceive)
 
mediamanager:addEventListener(Event.MEDIA_RECEIVE, mediareceive)
 
end)
 
end)
</source>
+
</syntaxhighlight>
  
 
{{Media}}
 
{{Media}}

Latest revision as of 14:31, 13 July 2023

Available since: Gideros 2016.1
Class: Media

Description

Allows user to select picture from gallery.

(string) = mediamanager:getPicture()

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)