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

showCamera output to AppDataDir triple size of saveToPhotoGallery

$
0
0

I've created a little test case when I save a photo taken with Titanium.Media.showCamera() to the Titanium.Filesystem.applicationDataDirectory. In this I tried to illustrate how the photo saved to the AppDataDir is almost triple the size of the photo saved to iPhones native photo gallery. What is the best way to reduce the file size in the AppDatDir?

Is there a way to have showCamera() automatically compress the image without resizing or the use of 3rd party plugins? Or should I have it save to the PhotoGallery/CameraRoll and copy that over to the local applicationDataDirectory?

Test case: app.js

/**
 * Why the different filesizes, and is there a workaround/fix?
 * SaveToPhotoGallery: 2.9MB
 * applicationDataDirectory > f.write: 9.1MB
 */
Titanium.UI.setBackgroundColor('#EEE');
 
var windowCamera = Ti.UI.createWindow({
    title:          "Camera test",
    height:         Ti.Platform.displayCaps.platformHeight,
    width:          Ti.Platform.displayCaps.platformWidth,
    fullscreen:     true,
    navBarHidden:   true
});
 
    Titanium.Media.showCamera({
        allowEditing:           false,
        saveToPhotoGallery:     true,
        mediaTypes:             [Ti.Media.MEDIA_TYPE_PHOTO],
        success: function(event) {
            var image       = event.media;
            var cropRect    = event.cropRect;
            var filename    = Titanium.Filesystem.applicationDataDirectory + "/"+ 'camera_photo' + new Date().getTime() + ".jpg";
            var f           = Titanium.Filesystem.getFile(filename);
 
            if (f.exists()) {
                Ti.API.info('File exist, delete before use:' + f.deleteFile());
                f = Titanium.Filesystem.getFile(filename);
            }
 
            f.write(image);
            windowCamera.backgroundImage = f.nativePath;
        },
        cancel: function() {
            Ti.API.info('canceled phtoo');
        },
        error: function(error) {
            var a = Titanium.UI.createAlertDialog({title:'Camera'});
 
            // set message
            if (error.code == Titanium.Media.NO_CAMERA)
                a.setMessage('Run on device...');
            else
                a.setMessage('Unexpected error: ' + error.code);
 
            a.show();
        }
    });
 
windowCamera.open();
Result is often almost triple its size, especially with images with much more detail then this of course. http://oi41.tinypic.com/b491yg.jpg (can't get the image tag working..)

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>