문제

Titanium / for an iOS App:

How can I manage to take a photo, and then use this one later in a new function to for example show the photo, and put a slightly larger duplicate of it with a transparency on top of itself?

도움이 되었습니까?

해결책

Note that I tried to edit the answer from Mitul Bhalia with the following, but the edit got knocked back. So here's how you do it:

After taking the image, you can store it as a variable in the global object, Alloy.Globals. You can then access this else where or later on in your app.

For example:

takePhotoButton.addEventListener('click', function(){
    Titanium.Media.showCamera({
    success:function(event) {
        if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {

            // Store the file in a variable 
            var image = event.media;

            // Store the image in the global object
            Alloy.Globals.temporaryImage = image;

        } else {
        alert("got the wrong type back ="+event.mediaType);
    }
    },
    ...

And somewhere else in your app, after the image has been stored, for example:

var anImage = Ti.UI.createImageView({ image: Alloy.Globals.temporaryImage })

Also note that extensive use of the global object can cause memory issues, so try not to overdo it.

다른 팁

If you want to save photo then you can use Alloy.Globals to save data globally so you can use it later.

Alloy.Globals.photo = blob object;

Here is how I am currently solving my problem:

takePhotoButton.addEventListener('click', function(){
    Titanium.Media.showCamera({
    success:function(event) {
        if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {

            // Store the file in a variable 
            var image = event.media;
            var filename = 'myPhoto.jpg';
            takenPhoto = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);
            takenPhoto.write(image);

        } else {
        alert("got the wrong type back ="+event.mediaType);
    }
    },
    ...

and then later I can use takenPhoto to show the picture I have taken with the camera. But I do not really know if this is the best way and if it is even correct, as I do not use 'var' to initiate takenPhoto. But if I use 'var' I cannot use takenPhoto outside of the function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top