Python for Android Tutorial #2 - Taking a picture
This is the second post about mobile development with Python.
It’s a short tutorial, just to help you to understand and learn how to work with Python for Mobile.
In this post you will see how to take pictures using Python and Android(Not compatible with iOS).
I - About the Tutorials
I’ll show you how to use each mobile API, like compass, camera, sensors, sound, and others. After the API, we will start to test some Python libs, as PyGame and OpenCV. I’m using Android with buildozer, but major part are compatible with iOS as well.
|Get updates||Follow @aron-bordin|
II - Index
- Tutorial #1 - Accelerometer
- Tutorial #2 - Camera
- Tutorial #3 - Kivy Designer
- Tutorial #4 - Debug
- Tutorial #5 - Android and iOS game with Python
- Tutorial #6 - Reading and saving user data
- Tutorial #7 - Use Android classes with PyJNIus
III - About this sample
Unfortunately Plyer camera still under development, so we will not be able to develop complex apps with it now.
It’s only compatible with Android, and we are not able to get camera preview.
In this version, we can start the camera intent with the command take_picture and choose a place to save the photo. So the app will open the Android camera, take a picture, and if you need to, you can read this image when necessary.
To show you how to use this class, I’ll show a simple sample, when the user click in the screen, a new image will be taken. A label will show where the image was saved. So if you are using Kivy or PySide for the UI, you can get this link and show the image.
IV - Creating the app
Create a new folder and create a new file named main.py.
Now, open your terminal and run the command bellow to create Buildozer spec file.
Open your buildozer.spec and edit it. In this tutorial we are going to use Plyer, so make sure to have the following line:
requirements = kivy, plyer
You can check my version here:
V - Let’s code it
First, check the app version and import all necessary libs:
Now, create basic UI:
Create our app class:
This picture was save at /storage/sdcard0/example.jpg.
Unfortunately camera still under development, so it’s not easy to create complex apps with it. And it’s compatible with Android only.
Thank you for reading, if you need something, feel free to comment here.