Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

set image from media.selectPhoto
Started by skulldred Jun 03 2018 12:33 AM

No replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

skulldred

[GLOBAL: userInfoPane.html]
skulldred
  • Observer

  • 1 posts
  • Corona SDK

Hi at all

 

i try to set an image from media.selectPhoto to a display.newCircle.

local Img = display.newCircle( 100, 100, 30 )
function pickImg( event )
  if media.hasSource( media.PhotoLibrary ) then
    media.selectPhoto( { mediaSource=media.PhotoLibrary, listener=onComplete, destination={ baseDir=system.DocumentsDirectory, filename="img.jpg" } } )
  else
    native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } )
  end
end
local function onComplete()
  timer.performWithDelay(1000, setPic, 1)
end
local function setPic ()
  local path = system.pathForFile( "img.jpg", system.DocumentsDirectory)
  
  local paint = {
    type = "image",
    filename = path
  }
  
  Img.fill = paint
  Img.fill.scaleX = 1
end

When i pick the first time an image it waits a second and set the picture to the circle.

But if i choose a second time the picture it try to set it immediately and the picture looks wired with lines.

Some times the app crash. i guess that happen cause the picture is still in copy process if i wait a second i have no problems.

 

Is there a better way and why the listener is not "reset"? When i choose the picture a second time why

 

Thanks a lot for ur help.

cheers SD




[topic_controls]
[/topic_controls]