Difference between revisions of "Media"
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | ||
<!-- GIDEROSOBJ:Media --> | <!-- GIDEROSOBJ:Media --> | ||
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | '''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | ||
Line 92: | Line 92: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Methods</translate> === | === <translate>Methods</translate> === | ||
− | + | [[Special:MyLanguage/mediamanager:deleteFile|mediamanager:deleteFile(path)]] ''<translate>deletes file at provided path</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:deleteFile|mediamanager:deleteFile(path)]] ''<translate>deletes file at provided path</translate>''<br/><!-- GIDEROSMTD:mediamanager:deleteFile(path) deletes file at provided path | + | <!-- GIDEROSMTD:mediamanager:deleteFile(path) deletes file at provided path --> |
− | + | [[Special:MyLanguage/mediamanager:getPicture|mediamanager:getPicture]] ''<translate>selects picture from gallery</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:getPicture|mediamanager:getPicture]] ''<translate> | + | <!-- GIDEROSMTD:mediamanager:getPicture() selects picture from gallery --> |
− | + | [[Special:MyLanguage/mediamanager:isCameraAvailable|mediamanager:isCameraAvailable]] ''<translate>returns true if you can get picture from camera</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:isCameraAvailable|mediamanager:isCameraAvailable]] ''<translate>returns true if you can get picture from camera</translate>''<br/><!-- GIDEROSMTD:mediamanager:isCameraAvailable() returns true if you can get picture from camera | + | <!-- GIDEROSMTD:mediamanager:isCameraAvailable() returns true if you can get picture from camera --> |
− | + | [[Special:MyLanguage/mediamanager:playVideo|mediamanager:playVideo(path, force)]] ''<translate>plays video file in given path (bool force to watch till the end, or quit playing on tap)</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:playVideo|mediamanager:playVideo(path, force)]] ''<translate> | + | <!-- GIDEROSMTD:mediamanager:playVideo(path, force) plays video file in given path (bool force to watch till the end, or quit playing on tap) --> |
− | + | [[Special:MyLanguage/mediamanager:postPicture|mediamanager:postPicture(path)]] ''<translate>adds picture from given path to gallery (or opens save file dialog on pc)</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:postPicture|mediamanager:postPicture(path)]] ''<translate> | + | <!-- GIDEROSMTD:mediamanager:postPicture(path) adds picture from given path to gallery (or opens save file dialog on pc) --> |
− | + | [[Special:MyLanguage/mediamanager:takePicture|mediamanager:takePicture]] ''<translate>allows user to provide picture input from camera</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:takePicture|mediamanager:takePicture]] ''<translate> | + | <!-- GIDEROSMTD:mediamanager:takePicture() allows user to provide picture input from camera --> |
− | + | [[Special:MyLanguage/mediamanager:takeScreenshot|mediamanager:takeScreenshot]] ''<translate>captures a screenshot of the app</translate>''<br/> | |
− | [[Special:MyLanguage/mediamanager:takeScreenshot|mediamanager:takeScreenshot]] ''<translate> | + | <!-- GIDEROSMTD:mediamanager:takeScreenshot() captures a screenshot of the app --> |
+ | |||
+ | [[Special:MyLanguage/Media.new|Media.new(path)]] ''creates a new Media object with provided image''<br/> | ||
+ | <!-- GIDEROSMTD:Media.new(path) creates a new Media object with provided image --> | ||
+ | [[Special:MyLanguage/Media.new|Media.new(width, height)]] ''creates a blank Media object with provided dimensions''<br/> | ||
+ | <!-- GIDEROSMTD:Media.new(width, height) creates a blank Media object with provided dimensions --> | ||
− | + | TO DO!<br/> | |
− | |||
'''Media:getPath()''' -- returns the path that was used to create object<br/> | '''Media:getPath()''' -- returns the path that was used to create object<br/> | ||
'''Media:getWidth()''' -- returns the width of the image<br/> | '''Media:getWidth()''' -- returns the width of the image<br/> |
Revision as of 21:54, 6 February 2020
Supported platforms:
Available since: Gideros 2016.1
Description
- Get image from Camera, gallery or file system
- Resize image
- Make copy of an image
- Take screenshots
- Play videos (for cutscenes)
- Manipulate pictures (getting/setting pixels)
- And much more...
Examples
Example 1.
--require plugin
require "media"
-- is camera available
print(mediamanager:isCameraAvailable())
-- take screenshot (no permission needed)
mediamanager:takeScreenshot()
-- get picture from gallery (*need read permission*)
mediamanager:getPicture()
-- save picture to sdcard/pictures folder (*need write permission*)
mediamanager:postPicture("gfx/ball.png")
Example 2.
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
Example 3. Save a picture on your phone or on your pc.
require "media"
-- draw your gfx
local source = Pixel.new(0xff00ff, 1, 128, 128)
-- create a render target and draw to it
local rt = RenderTarget.new(source:getWidth(), source:getHeight())
rt:draw(source)
-- save your render target to gideros documents folder
local myfilepath = "|D|mysavedpicture2.png"
rt:save(myfilepath)
-- create a new media and save your gfx
local media = Media.new(myfilepath)
-- android saved path = internal storage/pictures !!! NEED permission write external storage !!!
mediamanager:postPicture(myfilepath)
-- show your gfx on stage
local mybmprt = Bitmap.new(Texture.new(myfilepath))
mybmprt:setPosition(64, 64)
stage:addChild(mybmprt)
Notes
By resizing image you will actually resize the file of the image, so there is no going back to upscale it later.
getPicture method gives you copies of the image, so you won't harm the original.
The dimensions when resizing are all actual dimensions of the image and not logical dimensions in your project.
Methodsmediamanager:deleteFile(path) deletes file at provided path Media.new(path) creates a new Media object with provided image TO DO! |
EventsEvent.MEDIA_RECEIVE (e.path) -- path to image Constants |