将拍摄的照片按比例缩放至屏幕大小。

我可以使用以下代码拍照:

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 )

但是,如果图片太大,它不会缩小或缩放,我尝试了**local w =display.contentWidth**但是没有任何反应。我如何将照片缩放到完全匹配屏幕大小,可能需要在Y轴上进行缩放以填充屏幕。

点赞
用户2260604
用户2260604

如果您只想缩小图片,您可以采用以下两种方法:

1:使用显示对象的比例( http://docs.coronalabs.com/api/type/DisplayObject/scale.html

对象:缩放(xScale,yScale)

或者第二种解决方案,我怀疑这就是您要寻找的:

2:直接设置图像大小。

使用对象的object.width和object.height并设置相应的显示对象的内容宽度和内容高度来设置图像的宽度/高度。

将sessionComplete函数更改为以下内容:

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
2014-05-13 17:17:21
用户1993254
用户1993254

使用以下公式解决了这个问题

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
2014-05-15 13:00:54