Why is my Camera Image Scaled Up

Hi guys,

I’m using sample code here and when I ran it and tested it on my android device the image was scaled up so it looks as if it was zoomed in at the center of any image i took.

[lua]

– 

– Abstract: Camera sample app

– 

– Version: 1.2

– 

– Updated: September 21, 2011

– Update History:

– v1.1 Fixed logic problem where it said “session was cancelled”.

– v1.2 Added Android support.

– Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license

– Copyright © 2011 Corona Labs Inc. All Rights Reserved.]

– Supports Graphics 2.0


local centerX = display.contentCenterX

local centerY = display.contentCenterY

local _W = display.contentWidth

local _H = display.contentHeight

– Camera not supported on simulator.                    

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 bkgd = display.newRect( centerX, centerY, _W, _H )

bkgd:setFillColor( 0.5, 0, 0 )

local text = display.newText( “Tap anywhere to launch Camera”, centerX, centerY, nil, 16 )

local sessionComplete = function(event)

local image = event.target

print( "Camera ", ( image and “returned an image” ) or “session was cancelled” )

print( "event name: " … event.name )

print( "target: " … tostring( image ) )

if image then

– center image on screen

image.x = centerX

image.y = centerY

image:scale(.6, .6)

local w = image.width

local h = image.height

print( “w,h = “… w …”,” … h )

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

bkgd:addEventListener( “tap”, listener )

[/lua]

Thanks again,

Matt.

The camera produces a much larger file that will fit into your content area.  the scale to .6, .6 may not be enough to actually make it fit.

You might want to try something more like:

local s = display.contentWidth /  image.width if image.height \> image.width then      s = display.contentHeight / image.height end image:scale( s, s )

This has worked perfectly thanks for the help. Is there a method to saving these pictures too as a quick side question?

Thanks,

Matt.

There are several ways to save things.  Look at display.save() to start.

Rob

The camera produces a much larger file that will fit into your content area.  the scale to .6, .6 may not be enough to actually make it fit.

You might want to try something more like:

local s = display.contentWidth /  image.width if image.height \> image.width then      s = display.contentHeight / image.height end image:scale( s, s )

This has worked perfectly thanks for the help. Is there a method to saving these pictures too as a quick side question?

Thanks,

Matt.

There are several ways to save things.  Look at display.save() to start.

Rob