Difference between revisions of "Mediamanager:isCameraAvailable"

From GiderosMobile
(first attempt at creating methods for media plugin)
 
Line 13: Line 13:
 
=== <translate>Return values</translate> ===
 
=== <translate>Return values</translate> ===
 
'''Returns''' (bool) ''true'' if camera is available, ''false'' otherwise.
 
'''Returns''' (bool) ''true'' if camera is available, ''false'' otherwise.
 +
 +
=== Example ===
 +
<source lang="lua">
 +
require "media"
 +
mediamanager:addEventListener(Event.MEDIA_RECEIVE, function(e)
 +
    local media = Media.new(e.path)
 +
    media:resize(200, 200)
 +
    print(media:getPixel(1, 1))
 +
    for x = 50, 100 do
 +
        for y = 50, 100 do
 +
            media:setPixel(x, y, 255, 0, 0, 0.5)
 +
        end
 +
    end
 +
    media:save()
 +
    local bmp = Bitmap.new(Texture.new(e.path, true))
 +
    stage:addChild(bmp)
 +
end)
 +
 +
if mediamanager:isCameraAvailable() then
 +
    mediamanager:takePicture()
 +
else
 +
    mediamanager:getPicture()
 +
end
 +
</source>
  
 
<!-- {{Media}} -->
 
<!-- {{Media}} -->

Revision as of 02:45, 11 February 2020


Available since: Gideros 2016.1
Class: Media

Description

Checks if camera is available.

(bool) = mediamanager:isCameraAvailable()

Return values

Returns (bool) true if camera is available, false otherwise.

Example

require "media"
mediamanager:addEventListener(Event.MEDIA_RECEIVE, function(e)
    local media = Media.new(e.path)
    media:resize(200, 200)
    print(media:getPixel(1, 1))
    for x = 50, 100 do
        for y = 50, 100 do
            media:setPixel(x, y, 255, 0, 0, 0.5)
        end
    end
    media:save()
    local bmp = Bitmap.new(Texture.new(e.path, true))
    stage:addChild(bmp)
end)

if mediamanager:isCameraAvailable() then
    mediamanager:takePicture()
else
    mediamanager:getPicture()
end