Show image after closing the application and open novament

Asked

Viewed 82 times

0

I have this code, and with it I can take a photo and display the photo instead of the camera image right after closing the camera. But how to make last picture taken on camera appear when opening the application?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link rel="manifest" href="manifest.json">

    <!-- Descomente esse código para ativar o service worker
    <script>
      if ('serviceWorker' in navigator) {
        navigator.serviceWorker.register('service-worker.js')
          .then(() => console.log('service worker installed'))
          .catch(err => console.log('Error', err));
      }
    </script>-->

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>

    <script src="js/ng-cordova.min.js"></script>
    </head>
   <body ng-app="starter">

        <ion-pane>

          <ion-header-bar class="bar-stable">

            <!-- Título que está acima da imagem -->
            <h1 class="title col text-center">Câmera</h1>

          </ion-header-bar>

            <ion-content ng-controller="MainCtrl">  

             <img ng-src="{{srcImage || 'img/dummy.jpg'}}" id="srcImage" width="350 " height="350" style="display: block; margin: 0 auto;"/><br/>              
             <button class="button button-full button-positive" ng-click="takeImage() ">Tirar uma foto</button><br/>

           </ion-content>

        </ion-pane>
      </body>
    </html>

app js.

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var app = angular.module('starter', ['ionic','ngCordova'])

.run(function($ionicPlatform) {

  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });


})

app.controller('MainCtrl', function($scope, $cordovaCamera) {
    $scope.takeImage = function() {
        var options = {
            quality: 100,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.CAMERA,
            allowEdit: true,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 350,
            targetHeight: 350,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: true,
            correctOrientation: true
        };

        $cordovaCamera.getPicture(options).then(function(imageData) {
            $scope.srcImage = "data:image/jpeg;base64," + imageData;
        }, function(err) {
            // error
        });

    }
});
  • Well the code itself I would have to create but the logic is simple. 1º you must save the last image in some db (sqlite or localStorage). 2º when opening the screen, your app checks if this parameter exists (Ex: localStorage.lastImage.length > 0), if it exists it feeds the controller.

  • 1

    The photo is being saved in the device’s memory

  • the problem is that the memory can be dumped or reused depending on the process being used. on Android, when leaving it freezes the application leaving that in memory but, if the person really close the application, you lose that. so it’s interesting to save even in a txt...

  • I have no idea how to do this.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.