Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Duplicate image when take photo by camera or upload image to server.

$
0
0
  • Application type: mobile
  • Titanium SDK: Titanium 2.1.0.GA
  • Platform & version: Android 2.2
  • Device: Motorola Atrix 4G
  • Host Operating System: Windows 7
  • Titanium Studio: build: 2.1.0.201206251749
  • Hi, I just write very common thing with smart phone is upload image to server, the user can chose the image from gallery or take photo by camera. The problem is when I take a picture by camera (even I have set saveToPhotoGallery : false) application will save 2 image to the phone(one with name tiaxxx), so i disaple the function take pic by camera(only let user choose from gallery) even that when select an image and upload success to server, close application and open the gallery i also saw that the image is duplicated.
  • I spent two day to find the solution without success, I'm going to give up Titanium.
  • is this a bug of Titanium? I have seen this link but without answer https://jira.appcelerator.org/browse/TIMOB-6357
  • Here is my code.
    //Application Window Component Constructor
    function ApplicationWindow() {
        //load component dependencies
        var win = Ti.UI.createWindow({
                backgroundImage:'/images/gradientBackground.png',
                exitOnClose: true
            });
        //define a child view.
        /*
        var myImageView = Titanium.UI.createView({
                top:'50dp',
                width:'auto',
                height:'auto'
            });*/
     
        // define the image view to show image
        var imageView = Ti.UI.createImageView({
            image:'/images/no-images.jpg',
            //left:0,
            top:'50dp',
            height:'250dp',
            width:Ti.UI.FILL
        });
     
        //myImageView.add(imageView);
     
        // define the custom page heading here
        var ind=Titanium.UI.createProgressBar({
            width:'200dp',
            height:'50dp',
            min:0,
            max:1,
            value:0,
            style:Titanium.UI.iPhone.ProgressBarStyle.PLAIN,
            bottom:'50dp',
            message:'Uploading Image',
            font:{fontSize:'12dp', fontWeight:'bold'},
            color:'#888'
        });
     
     
        //define button to show gallery
        var fGaButton = Titanium.UI.createButton({
           title: 'From Gallery',
           top: '0dp',
           left:'0dp',
           width: '80dp',
           height: '40dp',
           font: {
                fontSize:'14dp'
            }
        });
        fGaButton.addEventListener('click',function(e){
     
            Ti.Media.openPhotoGallery({
                success:function(ev) {
                    imageView.setImage(ev.media);
                },
                error : function(error) {
                    alert('error');
            },
            allowEditing : false,
            saveToPhotoGallery : false,
            });
        });     
        //define button to show camera
        var fCaButton = Titanium.UI.createButton({
           title: 'From Camera',
           top: '0dp',
           right:'0dp',
           width: '80dp',
           height: '40dp',
           font: {
                fontSize:'14dp'
            }
        });
     
        var isCameraSupport = Ti.Media.isCameraSupported;
     
        if(isCameraSupport){
            fCaButton.addEventListener('click',function(e){
                Ti.Media.showCamera({
                    success:function(event) {
                        // called when media returned from the camera
                        Ti.API.debug('Our type was: '+event.mediaType);
                        if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
                            imageView.setImage(event.media);
                        } 
                    },
                    cancel:function() {
                        // called when user cancels taking a picture
                    },
                    error:function(error) {
                        // called when there's an error
                        var a = Titanium.UI.createAlertDialog({title:'Camera'});
                        a.setMessage('Unexpected error: ' + error.code);
                        a.show();
                    },
                    saveToPhotoGallery:false,
                    allowEditing:false,
                    mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
                });
            }); 
        }else {
            fCaButton.setEnabled(false);
        }
     
        //define a child view.
        var childView = Titanium.UI.createView({
            top:'5dp',
            width:'170dp',
            height:'auto'
        });
        childView.add(fGaButton);
        childView.add(fCaButton);
     
        var uploadButton = Titanium.UI.createButton({
           title: 'Upload',
           bottom:'5dp',
           //left:150,
           width: '80dp',
           height: '40dp'
        });
     
        uploadButton.addEventListener('click',function(e){
            ind.show();
            Ti.API.info('Upload start...................: ');
            var xhr = Titanium.Network.createHTTPClient();
            xhr.onerror = function(e) {
                Ti.API.info('IN ERROR ' + e.error);
            };
            xhr.onload = function() {
                alert('Upload success.');
                ind.hide;
            };
            xhr.onsendstream = function(e){
                ind.value = e.progress ;
                Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress);
            };
     
            // open the client
            xhr.open('POST','http://Myserver/upload.php');
     
            // send the data
            xhr.send({media:imageView.image ,APIKey:'xxxxx'});
     
        });
     
        win.add(childView);
        win.add(uploadButton);
     
        win.add(ind);
        win.add(imageView);
     
        return win;
    }
     
    //make constructor function the public component interface
    module.exports = ApplicationWindow;
    Am I doing something wrong? Or is there another method to solve this problem? Thanks and best regards, Trang.

Viewing all articles
Browse latest Browse all 8068

Trending Articles