Using Images and the Camera in App Inventor

You may also like...

27 Responses

  1. Drini says:

    Hello Ed,
    The photo taking and image displaying is quite simple. If you want more pictures at the same display, I think it gets tricky. I gave a try in making the option of taking two, three or four photos (displayed in a table arrangement), but I failed to make the blocks work.
    Usually you have one global declared value for Image, so in multiple images several global (empty) values are needed for them.
    In case there are one, two or three photos already taken, the block needs to check if they are valid and filled, before continuing to the next empty value. Seems I am not approaching this the right way. Can you recommend me a solution?

    Here’s my attempt. https://drive.google.com/file/d/0B4c2eCyvDxPWTlIwMkRyRzNNNG8/view?usp=sharing

    Thank you
    Drini

    • Edward M says:

      Drini,
      The problem with the “not” is that the value “get image1” does not evaluate to a true or false value. “not” only works if the value to the right can be converted to a true (including non-zero values, I think) or false (include zero, I think).

      Another way to keep track of which Image has a valid value is to set up a 2nd set of variable (such as ValidImage1, ValidImage2, ValidImage3…) and set those to true or false, to keep track of what is stored in Image1, Image2, Image3.

      My memory is that when I worked with Images, App Inventor does not currently support a “list” of images. If AI did support a list of Images, this would be a lot simpler.

      Ed

      • Drini says:

        Hi Ed, thank you for your reply. You were right regarding the “not” use. I was looking at the wrong place (the “Logic”) while I was actually aiming at “is empty” part (which was in “Text”). Once I started using the “is empty” part instead of “not” I did create blocks for every image. Of course, I cannot use lists but four images are enough.

        Thank you again for your insight.

        Cheers
        Drini

  2. aarthi says:

    I have ASUS tab. After clicking the photo. the tab displays, 2 buttons. Retake and Done. How many ever times I click Done, the screen does not go back to the app.

    • Edward M says:

      Are you running in the AI2 Companion? Yesterday I was having similar problems from time to time on a different app I am writing. Sometimes screens would come up blank or not at all. This occurred after several test runs of the app – and I eventually had to restart my phone (not just kill the AI2 Companion). Something odd was happening but I do not know what was going on.

      When I used “Build” to create the .apk file and then install that on my phone directly, the app ran fine. Wonder if you are encountering a similar problem?

      Ed

  3. Leela says:

    hi,im trying to build an app that contains different categories of images if we choose particular category that album will be displayed.Say for instance categories be fruits,flowers etc.If i click on fruits button all the images of fruits taken by me should be displayed.Here the images are taken by the user from camera.how to store these images under different cateogries and retrieve them.Please help.

  4. Leela says:

    hi,im trying to build an app that contains different categories of albums if we choose particular category that album will be displayed.Say for instance categories be fruits,flowers etc.If i click on fruits button all the images of fruits taken by me should be displayed.Here the images are taken by the user from camera.how to store these images under different cateogries and retrieve them.Please help.

    • Edward M says:

      I have not yet done much work with images. If other readers have worked with images, please jump in with a comment.

      Perhaps I will play with images later today to see what options there are for storing images.

      Ed

    • Edward M says:

      You can store images in Lists. Just use Add Items to List -> List to use, -> get Image.

      Then you can fetch any list item from the list, and assign it to an Image1 object on the screen to display the images you have.

      You could create a separate list variable for each category, or you could create a list that contains sublists (more complicated).

      I also just did a little check and it appears that you can store images in TinyDB, as well. I will need to do a lot more experimenting to figure out the possibilities of using images/camera, etc, in App Inventor apps. Looks like it might be able to do a lot.

      Hope that helps!

      Ed

  5. Paul Kidman says:

    Is there a way of getting a live view from the camera?
    I want to put templates / frames over the live view before i take the photo..

    • Edward M says:

      Paul, not exactly. App Inventor seems to launch a standard Android camera which runs independently of whatever you do in App Inventor. I understand your desire – I always use grid lines when shooting photos with cameras.

      Ed

      • Paul Kidman says:

        Thank you for the fast reply.
        The app i want to make will use my own grid lines.
        sad face.
        I wonder weather this is something they will update.
        Is there any thing else like app inventor, that would let me do this.

        • Edward M says:

          There might be a possibility if written using the much more complex Android Studio in the Java programming language and the Android SDK (this is not for programming beginners).

          I have not done very much with the camera and images and I do not know if you can do the grid overlay using the Android SDK directly.

          Another possibility – could you use a camera app that someone else has written? There are many free camera apps on the Google Play store and if someone has solved that grid lines problem, you might be able to use that. Then, in your App Inventor app, you may be able to launch that other camera app using the Connectivity | ActivityStarter to launch another app. When that app finishes, control returns to your App Inventor app. I do not know if this is the best path to try, but it is probably the next step I would look in to.

          Ed

  6. akithero says:

    Hello Ed,
    Im working on camera with image processing for my final year project. the project are to make an android app that take picture and peocess the image. Is it possible to use openCV or connected to MatLAB using app inventor?
    if not, can you recommend me any other method?

    Thank You
    Akithero

    • Edward M says:

      Akithero,
      In App Inventor, you can operate the camera (AI2 calls Android to do that) to take photos. The camera returns a photo image that can be used as an image, and you can store them in TinyDB too. But there is not much you can do directly in AI2 to analyze the image – yet.

      Last fall, App Inventor announced they are testing a new “extensions” feature that enables programmers to add new features to App Inventor. If you go here http://appinventor.mit.edu/extensions/ there is an ImageProcessor extension available for testing. It does not yet do a lot, but I suspect more feature will be coming in the future.

      Another way to do image analysis, eventually, might be to write the image analysis code in Java and the Android SDK. Then use ActivityStarter (under Connectivity in the Designer View) to launch the external app to do the image analysis, or more likely, have that separate app use the openCV library code base. I do not know if there is an easy way to transfer an AI2 image to an external app. I know you could assign the image to a Canvas background and you can take a “snapshot” of the Canvas and store that in an image file on the Android device.

      Unfortunately, I do not have access to MatLAB and it is really expensive to buy it. I wish I could use MatLAB as there are many things I would like to try with it. But that means I am not of much help when it comes to interfacing to MatLAB.

      I just had a comment on FB from someone that is using App Inventor code, and a link via Bluetooth to an Arduino, and then from the Arduino through an unspecified mechanism, to get data into MatLAB. I do not know if that would work for Image data in AI2. However, I did something similar a couple of years ago using the Android SDK instead of AI2. I wrote code for an Arduino that interfaced to a linear current sensor and the ADC on the Arduino to measure voltage and current in an external device. I had the Arduino send the measurements over the serial/USB interface to an app I wrote for Windows which read the data and logged it to a data file on the PC. The data files were then later analyzed in Microsoft Excel. My project also had code running on an Android phone, which was written in the Android SDK.

      I could see something similar using AI2 to write an Android app that collects the data into a file, which is then transferred to a PC. In fact, you could install something like DropBox on the Android and the PC – as you write data into the Android file, it would then automatically synchronize through DropBox to the PC. And there on the PC, you could read the data into MatLAB.

      I am thinking “out loud” as I write this – these are just ideas but perhaps they will spark an idea that solves your problem?

      Ed

      Ed

  7. ronel says:

    how to capture and save image to mysql in app inventor help me please

    • Edward M says:

      At this time, MIT App Inventor does not support MySQL. Instead, MIT AI works with Google Fusion Tables, which is very similar to an SQL database. It’s sufficiently complicated to set up, program and use, that I have several chapters about databases in my volume 3 – ebook, App Inventor 2 Databases and Files available for immediate download from the links on the http://appinventor.pevest.com web site.

      Ed

  8. Mike says:

    How to save image to a php external website?
    File will receive a post and do the save but sending it to the page cant seem to do!!!

    • Edward M says:

      I was away for a week on vacation, with much Internet! Off hand, I do not know how to save an image to a php external web site. I don’t know if this is possible from App Inventor code.

  9. vaibhav says:

    hey Ed,
    i want to build a camera app in which camera will open within the screen only and cover only the part of screen. can u tell me if it is possible using app inventor 2?

    • Edward M says:

      I have not used the camera feature in a while and I am traveling just at the moment. From what I remember, the camera app basically opens a generic Android camera app, which takes over the screen. Then, upon return, it returns an “image object” to your. I just checked – I do have a post on the camera component – check this out
      http://appinventor.pevest.com/?p=161

      Good luck to you!

      Ed

  10. jumpjack says:

    I read somewhere that pictures taken in this way cannot be saved to the gallery, is that true?
    Does it exist a workaround?

    • Edward M says:

      The camera component is pretty limited. It just fires up the generic Android camera app and takes a photo and passes that back to the App Inventor app as an “image object”. There’s not a lot that you can do with image objects, as best I can tell. Does the image get saved in the gallery? I don’t know off hand. I don’t have time to test that out – but its pretty easy. If you go to
      http://appinventor.pevest.com/?p=161

      There is a set of sample blocks to do a simple camera app and that could be tested/checked fairly quickly.

      Ed

  11. Aba E says:

    Hi Ed,
    The Camera “Take Picture” method in App Inventor only launches the android camera and does not actually take or snap the picture.
    Is it possible that once the android camera is launch and with a timer set, it can take pictures without human intervention?

    • Edward M says:

      I do not think an App Inventor app can control the actual camera – only launch the camera app.

      There might possibly be a way to do something using the StartActivity block which enables App Inventor apps to launch other apps on the device. What I am thinking is that IF that works, then would could launch the camera app, and IF the camera app can take a parameter to activate the shutter, then, perhaps something could be made to work. But all this is very speculative! I don’t know if any of it would work!

  12. Christina says:

    I try to run this code on a Moto X and after taking (or selecting) the picture, instead of it showing the new picture, the image disappears entirely. I can tell the file path is being saved, because I can still share it over social media. But, it’s not displaying on the screen. What am I doing wrong?

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress spam blocked by CleanTalk.
LinkedIn Auto Publish Powered By : XYZScripts.com