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

Thumbnails have larger file size than image file...

$
0
0

Hi all,

I must be doing something dumb, as my thumbnail image sizes are larger than the actual images!

The following code saves 2 images file from a single camera image: the image (file) is about 864k, the thumbnail (thumbFile) is 2.80mb...

Any help very much appreciated!

function doPhoto(){
 
    Titanium.Media.showCamera({
 
        success:function(event)
        {       
            console.log("success");
 
            if (Ti.Platform.name == "android" && Ti.Filesystem.isExternalStoragePresent()) {
                console.log("android");
 
                var mkdfs = require('dk.mikkendigital.mkdfs');
 
                var UUID =  Ti.Platform.createUUID();
 
                var img= event.media; 
                console.log(UUID);
 
                var file = Ti.Filesystem.getFile('file://' + mkdfs.externalFilesDir, UUID+'.jpg');
                file.write(img);
 
                var thumb = img;
 
                var w = thumb.width;
                var h = thumb.height;
 
                var imgW;
                var imgH;   
 
                if(w>h){
                    //landscape
                    imgW = 'auto';
                    imgH=64;
                }else{
                    //portrait
                    imgW =64;
                    imgH='auto';                
                }   
 
                var thumbView = Titanium.UI.createImageView({
                    image:thumb,
                    width:imgW,
                    height:imgH,
                }); 
 
                thumb = thumbView.toBlob();
 
                console.log(thumb);
                console.log(UUID);
                var thumbFile = Ti.Filesystem.getFile('file://' + mkdfs.externalFilesDir, UUID+'thumb.jpg');
                thumbFile.write(thumb);
 
 
        } else {
            alert('No external storage found!');
        }
 
 
        //Ti.App.fireEvent('app:fromTitanium', {message: "photo taken fine"});
 
        },
        cancel:function()
        {
        },
        error:function(error)
        {
          var a = Titanium.UI.createAlertDialog({title:'Camera'});
          if (error.code == Titanium.Media.NO_CAMERA)
          {
            a.setMessage('Please run this test on device');
          }
          else
          {
            a.setMessage('Unexpected error: ' + error.code);
          }
          a.show();
        },
        showControls:false, // don't show system controls
        //mediaTypes:Ti.Media.MEDIA_TYPE_PHOTO,
        autohide:false  // tell the system not to auto-hide and we'll do it ourself
    });
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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