media.capturePhoto and media.selectPhoto returns different scaled pictures

Hi!

My problem as as the above topic. I have the exact same image. When loaded in media.selectPhoto through image gallery, it scales perfectly. When i take the exact same image through media.capturePhoto, the scaling is deformed. I put them through the same listener so they should work the same. I have attached the two different scaling image . Is this due to some config issue? Please advise on this. Thanks!

Code as follows:

if(myData.uploadMode == 1) then if media.hasSource( media.Camera ) then   media.capturePhoto( { listener = onComplete} ) else   native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end else if media.hasSource( media.PhotoLibrary ) then   media.selectPhoto( { mediaSource = media.PhotoLibrary, listener = onComplete } ) else   native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end end

Hi @vincent.form,

What is the “scale” setting in your config.lua file? Also, can you show us the code for your “onComplete” listener function?

Thanks,

Brent

Hi Brent!

Thanks for the quick response! Heres the config and code snippets.

config.lua

--calculate the aspect ratio of the device local aspectRatio = display.pixelHeight / display.pixelWidth application = { &nbsp; &nbsp;content = { &nbsp; &nbsp; &nbsp; width = aspectRatio \> 1.5 and 800 or math.ceil( 1200 / aspectRatio ), &nbsp; &nbsp; &nbsp; height = aspectRatio \< 1.5 and 1200 or math.ceil( 800 \* aspectRatio ), &nbsp; &nbsp; &nbsp; scale = "letterBox", &nbsp; &nbsp; &nbsp; fps = 30, &nbsp; &nbsp; &nbsp; imageSuffix = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;["@2x"] = 1.3, &nbsp; &nbsp; &nbsp; }, &nbsp; &nbsp;}, &nbsp; &nbsp;notification =&nbsp; { &nbsp; &nbsp;iphone = { &nbsp; &nbsp; &nbsp; &nbsp;types = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"badge", "sound", "alert" &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp;} } }

onComplete Code

local function onComplete(event) &nbsp; &nbsp;rect = event.target; &nbsp; &nbsp;if(rect == nil) then &nbsp; &nbsp; rect2:removeSelf(); bgRect:removeSelf(); return true; &nbsp; &nbsp;end &nbsp; &nbsp;rect.x = display.contentWidth/2; &nbsp; &nbsp;rect.y = display.contentHeight/2; local scaleCount = display.contentWidth/rect.width; rect.maxScale = scaleCount\*2; rect:scale( scaleCount, scaleCount ) rect.originalScale = scaleCount; end

Hi @vincent.form,

What happens if you don’t scale the image in the onComplete function? Is there a reason why you’re using that specific scaling math instead of just placing the image?

Brent

Hi Brent,

I took out the scaling in the function but the problem still persist. I went one step further and tried taking pictures from the provided camera sample code in SDK. It had the same problem. It seems pictures taking with camera are always ** stretched horizontally  no such problem if loaded from gallery. **Below is a snapshot of the image taken from the camera sample code.

Regards,

Vincent

The Corona Simulator does try to use the Mac iSight camera.  However, you can’t look at it’s behavior as something you can expect your apps to do.  Try building for the device and run it that way.

Rob

Hi @vincent.form,

What is the “scale” setting in your config.lua file? Also, can you show us the code for your “onComplete” listener function?

Thanks,

Brent

Hi Brent!

Thanks for the quick response! Heres the config and code snippets.

config.lua

--calculate the aspect ratio of the device local aspectRatio = display.pixelHeight / display.pixelWidth application = { &nbsp; &nbsp;content = { &nbsp; &nbsp; &nbsp; width = aspectRatio \> 1.5 and 800 or math.ceil( 1200 / aspectRatio ), &nbsp; &nbsp; &nbsp; height = aspectRatio \< 1.5 and 1200 or math.ceil( 800 \* aspectRatio ), &nbsp; &nbsp; &nbsp; scale = "letterBox", &nbsp; &nbsp; &nbsp; fps = 30, &nbsp; &nbsp; &nbsp; imageSuffix = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;["@2x"] = 1.3, &nbsp; &nbsp; &nbsp; }, &nbsp; &nbsp;}, &nbsp; &nbsp;notification =&nbsp; { &nbsp; &nbsp;iphone = { &nbsp; &nbsp; &nbsp; &nbsp;types = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"badge", "sound", "alert" &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp;} } }

onComplete Code

local function onComplete(event) &nbsp; &nbsp;rect = event.target; &nbsp; &nbsp;if(rect == nil) then &nbsp; &nbsp; rect2:removeSelf(); bgRect:removeSelf(); return true; &nbsp; &nbsp;end &nbsp; &nbsp;rect.x = display.contentWidth/2; &nbsp; &nbsp;rect.y = display.contentHeight/2; local scaleCount = display.contentWidth/rect.width; rect.maxScale = scaleCount\*2; rect:scale( scaleCount, scaleCount ) rect.originalScale = scaleCount; end

Hi @vincent.form,

What happens if you don’t scale the image in the onComplete function? Is there a reason why you’re using that specific scaling math instead of just placing the image?

Brent

Hi Brent,

I took out the scaling in the function but the problem still persist. I went one step further and tried taking pictures from the provided camera sample code in SDK. It had the same problem. It seems pictures taking with camera are always ** stretched horizontally  no such problem if loaded from gallery. **Below is a snapshot of the image taken from the camera sample code.

Regards,

Vincent

The Corona Simulator does try to use the Mac iSight camera.  However, you can’t look at it’s behavior as something you can expect your apps to do.  Try building for the device and run it that way.

Rob