Time for action – loading pictures for a mobile device

Maybe one day it will be possible for us to bring in images from the user's desktop computer photo application or from their web camera, but for now, these features only work on mobile devices.

LiveCode can call upon the native photo library and camera apps. We will test both of these on Android and iOS, but of course, only if your device has some saved images and a camera. For Kindle Fire, which doesn't have a camera, make sure that you save some pictures in the Gallery app, so that we can at least try loading those. Follow these steps to load pictures for a mobile device:

  1. Copy the Test button from the DatePicker card and paste it twice on the Pictures card. Change the name of the buttons to Test Camera and Test Library.
  2. Edit the script of the test camera button to be:
    on mouseUp
    mobilePickPhoto "camera"
    end mouseUp
  3. Edit the script of the test library button to be:
    on mouseUp
    mobilePickPhoto "library"
    end mouseUp
  4. As we test the loading of pictures, the image that is loaded will lie on top of the test buttons, stopping us from returning to the menu card. To solve this issue, add this to the card script:
    on mouseUp
    if word 1 of the target is "image" then delete the target
    end mouseUp
  5. Go in the Standalone Application Settings and select Android.
  6. We have to ask the Android OS permission to use the camera and store the image, so check the boxes for Camera and Write External Storage:
    Time for action – loading pictures for a mobile device
  7. Repeat the steps for testing on your Android device, or installing on your iOS device.
  8. Once the app is running on your device, touch Pictures on the first screen and then Test Library. You should see typical OS-specific options to choose a picture from your library or gallery.
  9. The picture you have selected is loaded on the card window and will fill most of the screen, obscuring our test and menu buttons. The card script we entered gives you the ability to touch the image in order to delete it so that you can then try another test.
  10. Try the Test Camera button. You will see the OS-specific camera application and when you have taken a picture and touched the Use or Ok button in the camera application, the image will be placed on the Pictures card.

What just happened?

These simple scripts illustrate how LiveCode is able to call the OS-specific applications to do what would otherwise take a lot of coding. What's more, as later iOS and Android OS versions are released, the same simple scripts activate the more advanced features that Apple and Google will have implemented.

Pop quiz – getting the big picture

Q1. We take so much for granted when it comes to improvements in technology. You might feel hard done by if your phone's camera is a measly 2 megapixels, but think back to how things were long ago and how big a picture you were used to seeing. In terms of the number of pixels, how many original Macintosh screens can fit in the area shown by a single 8 megapixel photo?

  1. 4
  2. 15
  3. 24
  4. 45

Answer: 45!

The original Mac had a screen that was 512 x 342 pixels. This will fit more than 45 times in the area of an 8 megapixel photo.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset