Picture is saved rotated

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Picture is saved rotated

Post by simon.schvartzman » Wed Feb 08, 2017 11:08 pm

I have the attached stack that takes a picture using the celular camera, without human intervention, and saves it to the device album.

Everything works OK with the device in Portrait mode, but when the mobile is in landscape the picture gets saved rotated by 90 degrees and I haven't been able to fix it, despite the hints I got on related posts ... :(

This is the code

Code: Select all

on mouseUp
   -- set the virtual camera
   cameraControlCreate"myFirstCamera"
   cameraControlSet "myFirstCamera", "device", "rear"
   cameraControlSet "myFirstCamera", "rect", the rect of image "Img1" 
   cameraControlSet "myFirstCamera", "visible", true
   -- take the picture and show it 
   cameraControlDo "myFirstCamera", "takePicture"
   put the result into image "Img1"  
   cameraControlSet "myFirstCamera", "visible", false
  -- save the picture
   put the long ID of the last image into tImageID
   mobileExportImageToAlbum tImageID
end mouseUp
Looking forward to get help from the gurus...
Attachments
Take&Save.livecode.zip
(2.36 KiB) Downloaded 158 times

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Picture is saved rotated

Post by simon.schvartzman » Thu Feb 09, 2017 3:08 pm

Using the answers from Richmond62, Bernd and Klaus on this post http://forums.livecode.com/viewtopic.php?f=9&t=28732
I have updated my code and now I can rotate the image but I'm getting a "not a supported format" error when I try to save it to the album.

What am I missing? How to fix it? I'm working on this for several days with no success.
Thanks

Code: Select all

on mouseUp
   -- clean previous image
   set the visible of img "Img1" to false
   set the width of img "Img1" to 300
   set the height of img "Img1" to 300
   set the locked of img "Img1" to true
   
   -- set the virtual camera
   cameraControlCreate"myFirstCamera"
   cameraControlSet "myFirstCamera", "device", "rear"
   cameraControlSet "myFirstCamera", "rect", the rect of img "Img1" 
   cameraControlSet "myFirstCamera", "visible", true
   
   -- take the picture and show it 
   cameraControlDo "myFirstCamera", "takePicture"
   put the result into img "Img1" 
   cameraControlSet "myFirstCamera", "visible", false
   set the visible of img "Img1" to true
   
   -- rotate picture according to device orientation
   put mobileDeviceOrientation() into theInterfaceOrientation
   
   switch theInterfaceOrientation
      case "Landscape Left"
         set the angle of img "Img1" to the angle of img "Img1" + 90   
         break
      case "Landscape Right"
         set the angle of img "Img1" to the angle of img "Img1" - 90   
         break
      case "Portrait upside down"
         set the angle of img "Img1" to the angle of img "Img1" + 180   
         break
   end switch
   
   set the locked of img "Img1" to true
   import snapshot from img "Img1"
   delete img "Img1"
   set the name of last img to "Img1"
   
   -- save the picture
   put the long ID of the last img into tImageID
   mobileExportImageToAlbum tImageID
   put the result into temp
   answer temp
   
end mouseUp


Simon
________________________________________
To ";" or not to ";" that is the question

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Picture is saved rotated

Post by Klaus » Thu Feb 09, 2017 3:39 pm

Hi Simon,

two things:
1. "locked" is no valid LC property, please use the correct "lockloc"!
2. Set the paintcompression first to a value that will be accepted by the OS.
Obviously the default value is not compatible with iOS:

Code: Select all

...
  end switch
  set the lockloc of img "Img1" to true
  set the paintcompression to "jpeg" 
  ## or "png"
  import snapshot from img "Img1"
...
Hope that helps!


Best

Klaus

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Picture is saved rotated

Post by simon.schvartzman » Thu Feb 09, 2017 4:13 pm

Klaus, many many thanks! It works OK now.

As always you have all the answers...

Cheers!
Simon
________________________________________
To ";" or not to ";" that is the question

Post Reply

Return to “Talking LiveCode”