Bruno Almeida
Bruno Almeida

Reputation: 166

Resize photo in Appcelerator Titanium before save

I'm having a little trouble in saving a photo with Appcelerator.

I'm taking a photo and saving it, okay, thats work and here is the code:

var cameraOverlay = Ti.UI.createView({
    width:'100%',
    height:'100%'
});

var porcoOverlay = Ti.UI.createView({
    width: '90%',
    height: '100%',
    left: 0,
    top: 0
});
var porco = Ti.UI.createImageView({
    width: 200,
    height: 238,
    top: 10,
    left: 10,
    image:'images/pig.png',
    touchEnabled: false
});
porcoOverlay.add(porco);
cameraOverlay.add(porcoOverlay);

var menuOverlay = Ti.UI.createView({
    width: '10%',
    height: '100%',
    right: 0,
    top: 0
});
var takeFoto = Ti.UI.createButton({
    title: 'PH',
    bottom: 10,
    right: 10
});
menuOverlay.add(takeFoto);
cameraOverlay.add(menuOverlay);



Ti.Media.showCamera({
    showControls:true,
    overlay: cameraOverlay,
    saveToPhotoGallery: true,
    success:function(event) {

        var cropRect = event.cropRect;
        var image = event.media;

        var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
        f.write(image);

    }
});

takeFoto.addEventListener('click',function(){
    Ti.Media.takePicture();
});

And here are my problem:

1 - The autofocus doesn't work;

2 - The image resolution is always: 320*240;

3 - I want to join overlay with the photo and save;

Can anyone help me?

Upvotes: 1

Views: 5040

Answers (2)

Siyanda
Siyanda

Reputation: 1

MV.utils.ImageUtils.resize(image, 500, 500);

Upvotes: -1

MRT
MRT

Reputation: 1610

@Bruno Almeida Your Code is almost Right. According this Query you want to save image with your Predefine Height and Width (Pixels). If Yes, then you Can try this Example This one is very use for me I think alos your. for Help ! understand This code

var ImageFactory = require('ti.imagefactory');
// Save your Image 

savedFile.write(event.media);
// Read you Image in Blob Format                    
var blob = savedFile.read();

//  Resize this image through use ImageFactory Module.

newBlob = ImageFactory.imageAsResized(blob, { width:300, height:300, quality:ImageFactory.QUALITY_LOW });
  savedFile.write(newBlob);
  blob = savedFile.read();

Upvotes: 2

Related Questions