This is a follow-up to the thread:
http://forums.coronalabs.com/topic/55530-possible-to-resize-jpg-images/
In addition to the scaling problems described in the other thread it turns out that calling media.capturePhoto() is restarting my app about 50% of the time!
\_W = display.contentWidth \_H = display.contentHeight local function itemPhotoOnComplete( event ) print("itemPhotoOnComplete() - START") if (event.completed == true) then local photo = event.target photo.x = \_W/2 photo.y = \_H/2 print(" Original photo dimensions = (" .. photo.width .. " x " .. photo.height .. ")") local scaling = 0.25 local scaledW = math.floor(photo.width \* scaling) local scaledH = math.floor(photo.height \* scaling) -- Rescale, save and remove photo print(" Scaled photo dimensions = (" .. scaledW .. " x " .. scaledH .. ")") photo:scale(scaling, scaling) display.save(photo, "img.jpg", system.TemporaryDirectory) photo:removeSelf() photo = nil -- Show rescaled image loadedImage = display.newImage("img.jpg", system.TemporaryDirectory, \_W\*0.5, \_H\*0.5) print(" Loaded image size = (" .. loadedImage.width .. " x " .. loadedImage.height .. ")") end print("itemPhotoOnComplete() - END") end local function takePhotoTouchHandler(event) print("takePhotoTouchHandler - START") if (event.phase == "ended") then -- Get image from camera if media.hasSource( media.Camera ) then print("Camera detected - starting camera") media.capturePhoto( { listener = itemPhotoOnComplete } ) else native.showAlert("Error", "No camera found", { "OK" } ) end end print("takePhotoTouchHandler - END") end print("\n\nApp started") local takePhoto = display.newText("PRESS HERE TO TAKE PHOTO", \_W\*0.5, \_H\*0.9, native.systemFont, 40) takePhoto:addEventListener("touch", takePhotoTouchHandler)
A typical log looks like this:
I/Corona (16610): App started
I/Corona (16610): takePhotoTouchHandler - START
I/Corona (16610): takePhotoTouchHandler - END
I/Corona (16610): takePhotoTouchHandler - START
I/Corona (16610): takePhotoTouchHandler - END
I/Corona (16610): takePhotoTouchHandler - START
I/Corona (16610): Camera detected - starting camera
I/Corona (16610): takePhotoTouchHandler - END
V/Corona (16610): Downsampling image file ‘/storage/emulated/0/Pictures/Picture26.jpg’ to fit max pixel size of 4096.
I/Corona (16610): itemPhotoOnComplete() - START
I/Corona (16610): Original photo dimensions = (1494 x 2656)
I/Corona (16610): Scaled photo dimensions = (373 x 664)
V/Corona (16610): Downsampling image file ‘/storage/emulated/0/Pictures/Picture26.jpg’ to fit max pixel size of 4096.
I/Corona (16610): Loaded image size = (504 x 896)
I/Corona (16610): itemPhotoOnComplete() - END
I/Corona (16610): takePhotoTouchHandler - START
I/Corona (16610): takePhotoTouchHandler - END
I/Corona (16610): takePhotoTouchHandler - START
I/Corona (16610): takePhotoTouchHandler - END
I/Corona (16610): takePhotoTouchHandler - START
I/Corona (16610): Camera detected - starting camera
I/Corona (16610): takePhotoTouchHandler - END
V/Corona (20268): > Class.forName: network.LuaLoader
V/Corona (20268): < Class.forName: network.LuaLoader
V/Corona (20268): Loading via reflection: network.LuaLoader
I/Corona (20268): Platform: SM-G900F / ARM Neon / 5.0 / Adreno ™ 330 / OpenGL ES 3.0 V@84.0 AU@ (CL@) / 2015.2590
V/Corona (20268): > Class.forName: plugin.fuse.LuaLoader
V/Corona (20268): WARNING: Could not load ‘LuaLoader’
V/Corona (20268): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona (20268): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona (20268): Loading via reflection: CoronaProvider.licensing.google.LuaLoader
I/Corona (20268):
I/Corona (20268):
I/Corona (20268): App started
The first part of the log shows a “lucky” call to media.capturePhoto().
The second part of the log shows a “unlucky” call to media.capturePhoto(), where calling media.capturePhoto() results in the app restarting without any ado - no warnings, not error messages. The listener is never called. The app restarts somewhere between the call to media.capturePhoto() and the listener and I’m powerless to do anything about it.
Where do I go from here to find out what is happening?