Replace image from camera

Hello everyone,

I used this code to adjust the size and the position of an image taken from camera:

local onComplete = function(event)

            local photo = event.target

            photo.x = 745;

            photo.y = 380;

           

            photo.xScale = 0.07;

            photo.yScale = 0.07;

            guy:remove(head);

            guy:insert(photo);

           

end

if media.hasSource( media.Camera ) then

            media.show( media.Camera, onComplete )

else

            native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )

end

Is it possible replace the image from camera with the same size than the image will be replaced?

Is it posible to adjust  different size for back and front camera?

For example:

Front camera:    photo.xScale = 1 

                          photo.yScale = 1

Back camera:    photo.xScale = 0.5 

                          photo.yScale = 0.5

I will really appreciate your help!

Many Thanks!

@Victor 

  1. Welcome the the community.

  2. media.show() is deprecated.  You shouldn’t use it any more: https://docs.coronalabs.com/daily/api/library/media/show.html

  3. Question: Are you saying:

  • You have a display object (say a 75 x 100 rectangle) with an image fill, AND
  • You take a photo with the camera, AND
  • You want to scale the camera image to fill the 75x100 rectangle exactly?

If you said, “Yes” to all 3 questions, then there is a way, but you have to scale the image to best fit width or height and be sure you don’t over-shrink it.

The solution would be something similar to this ( using media.capturePhoto()):

local myObj = display.newImageRect( "placeholder.jpg", 75, 100) myObj.x = display.contentCenterX myObj.y = display.contentCenterY local function onComplete( event ) local photo = event.target local scale1 = myObj.width/photo.width local scale2 = myObj.height/photo.height local scale = scale1 if( scale1 \* photo.height \< myObj.height ) then scale = scale2 end myObj.fill = { type = "image", filename = event.filename, baseDir = event.baseDir } myObj.fill.scaleX = scale myObj.fill.scaley = scale display.remove( photo ) end if media.hasSource( media.Camera ) then media.capturePhoto( { listener = onComplete } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end
  1. Please format future code posts (see image below):

formatyourcode.jpg

PS - Sources for code and concepts (for future reference):

@roaminggamer

 

Hello, 

 

Thank you very much for your help. Really appreciate it. Sorry I iforgot to mentioned that I am designer and working with KWIK.

 

Just tried all the steps you recommended me but does not work. 

 

Sorry, just wanted to know if could be able to be add  a button in the KWIK program to add your code and if YES, do you know how?

 

I am not working with codes so would really be grateful if you know how to sync booth.

 

Many thanks in advance for your help. 

 

Victor

@Victor,

I’m afraid I can’t help you there.  I don’t own Photoshop or Kwik.  

-Ed

@Victor 

  1. Welcome the the community.

  2. media.show() is deprecated.  You shouldn’t use it any more: https://docs.coronalabs.com/daily/api/library/media/show.html

  3. Question: Are you saying:

  • You have a display object (say a 75 x 100 rectangle) with an image fill, AND
  • You take a photo with the camera, AND
  • You want to scale the camera image to fill the 75x100 rectangle exactly?

If you said, “Yes” to all 3 questions, then there is a way, but you have to scale the image to best fit width or height and be sure you don’t over-shrink it.

The solution would be something similar to this ( using media.capturePhoto()):

local myObj = display.newImageRect( "placeholder.jpg", 75, 100) myObj.x = display.contentCenterX myObj.y = display.contentCenterY local function onComplete( event ) local photo = event.target local scale1 = myObj.width/photo.width local scale2 = myObj.height/photo.height local scale = scale1 if( scale1 \* photo.height \< myObj.height ) then scale = scale2 end myObj.fill = { type = "image", filename = event.filename, baseDir = event.baseDir } myObj.fill.scaleX = scale myObj.fill.scaley = scale display.remove( photo ) end if media.hasSource( media.Camera ) then media.capturePhoto( { listener = onComplete } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end
  1. Please format future code posts (see image below):

formatyourcode.jpg

PS - Sources for code and concepts (for future reference):

@roaminggamer

 

Hello, 

 

Thank you very much for your help. Really appreciate it. Sorry I iforgot to mentioned that I am designer and working with KWIK.

 

Just tried all the steps you recommended me but does not work. 

 

Sorry, just wanted to know if could be able to be add  a button in the KWIK program to add your code and if YES, do you know how?

 

I am not working with codes so would really be grateful if you know how to sync booth.

 

Many thanks in advance for your help. 

 

Victor

@Victor,

I’m afraid I can’t help you there.  I don’t own Photoshop or Kwik.  

-Ed