2014-05-13 65 views
2

我可以使用此代码拍照:规模拍摄的照片,以屏幕尺寸

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) 

但如果画面是大不缩小或缩小,我已经试过当地W = display.contentWidth但没有任何事情发生。我如何将照片缩放到精确的屏幕尺寸,可能需要在Y轴上缩放以填满屏幕

回答

0

通过使用该方程问题解决了

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 
4

如果您只是想缩小图片的大小,可以采用两种方法来实现。

1:显示对象(http://docs.coronalabs.com/api/type/DisplayObject/scale.html

object:scale(xScale, yScale) 

或我怀疑第二个解决方案上的使用规模,你在找什么

2:直接设置图像大小。

使用object.width和object.height设置图像宽度/高度并设置显示对象的各自contentWidth和ContentHeight。

更改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