1 Reply Latest reply on May 22, 2012 7:20 PM by Prem Radhakrishnan

    CameraUI problems with Android (Samsung Galaxy Tab 10.1)

    Prem Radhakrishnan Level 1

      I am using very basic code for capturing an image with CameraUI , here is the code this is from the xpenseit application sample by Christophe Coenraets and Holly Schinsky

      http://devgirl.org/2011/10/31/flex-mobile-development-building-tablet-apps-full-example-wi th-source-code/. The problem is that between the camera.launch and the trace("picture received") the delay is about a minute and a half , any ideas on whats going on ?

       

      PS:I tried to replace this with the Video & Camera classes and my own UI but the problem there that I had is that the pictures captured were very poor and very small.

       

       

       

      public function takePicture():void

                                    {

                                              var cameraUI:CameraUI = new CameraUI();

                                              cameraUI.addEventListener(MediaEvent.COMPLETE, cameraUtil_fileReadyHandler);

                                              cameraUI.launch(MediaType.IMAGE);

       

                                    }

       

       

      protected function cameraUtil_fileReadyHandler(event:MediaEvent):void

                                    {

                                              // TODO Auto-generated method stub

                                              trace("picture received");

                                              var mediaPromise:MediaPromise = event.data;

                                              if (mediaPromise.file == null)

                                              {

                                                        // For iOS we need to load with a Loader first

                                                        var loader:Loader = new Loader();

                                                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleted);

                                                        loader.loadFilePromise(mediaPromise);

                                                        return;

                                              }

                                              else

                                              {

                                                        // Android we can just dispatch the event that it's complete

                                                        var file:File = new File(mediaPromise.file.url);

                                                        trace(file.url);

                                              }

                                    }

       

       

                                    protected function loaderCompleted(event:Event):void

                                    {

                                              var loaderInfo:LoaderInfo = event.target as LoaderInfo;

                                              if (CameraRoll.supportsAddBitmapData)

                                              {

                                                        var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height);

                                                        bitmapData.draw(loaderInfo.loader);

                                                        var file:File = File.applicationStorageDirectory.resolvePath("receipt" + new Date().time + ".jpg");

                                                        var stream:FileStream = new FileStream()

                                                        stream.open(file, FileMode.WRITE);

                                                        var j:JPEGEncoder = new JPEGEncoder();

                                                        var bytes:ByteArray = j.encode(bitmapData);

                                                        stream.writeBytes(bytes,0,bytes.bytesAvailable);

                                                        stream.close();

                                                        trace(file.url);

                                                        //dispatchEvent(new CameraEvent(CameraEvent.FILE_READY, file));

                                              }

                                    }