Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Take A Picture, Preview and Upload

I am trying to create a form using the twitpix example.

Where I take a photo from the camera and or the photo albumn.

I then trying to assign it to the imageView as a preview,
once the user fills 1 text field for the message, it sends to twitpix.

It's not working, how do you assign the imageView the taken image, and then send the full sized image to the server?

I tried toImage, and toBlog and its not the right sized image.

  Titanium.Media.showCamera({


            success:function(event)
            {


                var image = event.media;

                // set image view
                imageView.image = image;


            },
            cancel:function()
            {

            },
            error:function(error)
            {
                // create alert
                var a = Titanium.UI.createAlertDialog({title:'Camera'});

                // set message
                if (error.code == Titanium.Media.NO_CAMERA)
                {
                    a.setMessage('Device does not have video recording capabilities');
                }
                else
                {
                    a.setMessage('Unexpected error: ' + error.code);
                }

                // show alert
                a.show();
            },
            saveToPhotoGallery:true,
            allowImageEditing:true
— asked June 24th 2010 by M B
  • iphone
  • mobile
  • upload
0 Comments

2 Answers

  • to save the image to the app's directory:

    var image = event.media;
    var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "savedImage.jpg");
    f.write(image);
    

    rocksteady,
    danno~

    — answered June 24th 2010 by danno watts
    permalink
    5 Comments
    • How do I show say a 50x50 thumb, but still submit the full sized image?

      Global var?

      — commented June 24th 2010 by M B
    • total code:

      var image = event.media;
      var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "savedImage.jpg");
      f.write(image);
      
      var imageView = Titanium.UI.createImageView({
          height:50,
          width:50,
              image:f.nativePath;
      
      });
      win.add(imageView);
      

      rocksteady,
      danno~

      — commented June 24th 2010 by danno watts
    • that help ya out?

      rocksteady,
      danno~

      — commented June 25th 2010 by danno watts
    • I will try this out, I have this in event listeners, not sure if I can access them.

      — commented June 25th 2010 by M B
    • This Crashes the simulator

      Titanium.Media.showCamera({
      
      
                  success:function(event)
                  {
      
      
                         var image = event.media;
                         var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "savedImage.jpg");
                         f.write(image);
      
                          imageView = Titanium.UI.createImageView({
                                    height:200,
                                    width:200,
                                    top:50,
                                    left:60,
                                    backgroundColor:"#000",
                                    borderColor:'#FFF',
                                    borderWidth:5,
                                    borderRadius:5,
                                    image:f.nativePath
                            });
      
      
      
                         formView.add(imageView);
      
                         //Add Elements to Modal Window
      
                         uploadWin.open({modal:true});
                         formView.add(whatText);
                         formView.add(whereText);
                         formView.add(upload);
                         formView.add(atLabel);
                         uploadWin.add(formView);
                         upload.show();
                  },
      

      — commented June 25th 2010 by M B
  • I was able to get it working, by putting my listeners inside the success function.

    The problem now is no matter what I do to clear it, if i want to rerun the function the image view has the previous image stuck inside of it.

    — answered June 25th 2010 by M B
    permalink
    2 Comments
    • no matter what you do to clear what exactly?

      you would define the creation of the imageView ( and adding it to the window ) outside of the success result from the camera and then just define the "image" property from within the success results.

      — commented June 25th 2010 by danno watts
    • try setting a different filename and delete the one. i think it's cached by the system.

      — commented January 30th 2013 by Keith Levi Lumanog
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.