Question

I can take a photo using this code :

local centerX = display.contentCenterX
local centerY = display.contentCenterY

local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model")
if (isXcodeSimulator) then
     local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})    
end

local sessionComplete = function(event) 
    local image = event.target

    if image then
        image.x = centerX
        image.y = centerY
        local w = image.width
        local h = image.height
    end
end

local listener = function( event )
    if media.hasSource( media.Camera ) then
        media.capturePhoto( { listener = sessionComplete } )
    else
        native.showAlert("Corona", "Camera not found.")
    end
    return true
end

trigger:addEventListener( "tap", listener )

But if the picture is to big it doesn't zoom out or scale down, i have tried local w =display.contentWidth but nothing's happening. How can i scale the photo to the exact screen size, probably need to scale in the Y axis to fill the screen

Was it helpful?

Solution 2

Solved the problem by using this equation

image.contentWidth / image.contentHeight * display.contentHeight

local sessionComplete = function(event) 
     local image = event.target
     if image then
     imgWidth = image.contentWidth / image.contentHeight * display.contentHeight 
         image.x = centerX
         image.y = centerY
         image.width = imgWidth
         image.height = display.contentHeight
     end
end

OTHER TIPS

If you simply wish to scale the picture down there are two ways you can do that.

1: Use scale on the display object (http://docs.coronalabs.com/api/type/DisplayObject/scale.html)

object:scale(xScale, yScale)

or the second solution which I suspect is what you are looking for

2: Set the image size directly.

Set the image width/height using object.width and object.height and setting the respective contentWidth and ContentHeight of your display object.

Change the sessionComplete function to the following

local sessionComplete = function(event) 
     local image = event.target
     if image then
         image.x = centerX
         image.y = centerY
         image.width = display.contentWidth
         image.height = display.contentHeight
     end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top