简体   繁体   English

钛将照片添加到特定的画廊

[英]Titanium add photo to specific gallery

So I have the following which works real nice as is: 因此,我有以下内容按原样很好工作:

 button.addEventListener("click", function(e){
    Titanium.Media.showCamera({
        success:function(e){
            if(e.mediaType === Titanium.Media.MEDIA_TYPE_PHOTO){
                var imageView = Titanium.UI.createImageView({
                    image: e.media,
                    width: 'auto',
                    height: 'auto',
                    top: 50,
                    zIndex: 1
                });
                win.add(imageView);
            } else {
                alert("Only Photos aloud");
            }
        },
        error:function(e){
            alert("There was an error");
        },
        cancel:function(e){
            alert("The event was cancelled");
        },
        allowEditing: true,
        saveToPhotoGallery: true,
        mediaTypes:[Titanium.Media.MEDIA_TYPE_PHOTO,Titanium.Media.MEDIA_TYPE_VIDEO],
        videoQuality:Titanium.Media.QUALITY_HIGH
    }); 
});

saveToPhotoGallery just adds the taken photo to the default gallery in the iOS Photos App. saveToPhotoGallery只是将拍摄的照片添加到iOS Photos App中的默认画廊。 I need to add the photo to a specific folder in the iOS Photos App though. 我需要将照片添加到iOS Photos App中的特定文件夹中。 Has anyone an idea how I could do this from with Titanium ? 有谁知道如何用Titanium做到这一点? I have been searching the intewebs but have not found anything on how to add a taken photo to a specific folder. 我一直在搜索互联网,但未找到有关如何将拍摄的照片添加到特定文件夹的任何信息。

Thank for the help guys 谢谢你们的帮助

Chris 克里斯

But, let me specify that the file can be save in the Application Directory only in IOS but in android you can save it in the externalStorage. 但是,让我指定该文件只能在IOS中保存在应用程序目录中,但是在android中,您可以将其保存在externalStorage中。 You can have look at the documentation through the below link : 您可以通过以下链接查看文档:

https://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage https://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage

You can easily save the file to your folder using the following code : 您可以使用以下代码轻松地将文件保存到文件夹中:

if (OS_ANDROID) {
    var f12 = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory);
} else {
    var f12 = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
}

var galleryImg = e.media;
var fileToSave = null;
var fileName = 'IMG' + todayDate + "HB" + Ti.App.Properties.getInt('imgCounter') + '.jpg';
if (OS_ANDROID) {
    fileToSave = Titanium.Filesystem.getFile(f12.resolve(), fileName);
} else {
    fileToSave = Titanium.Filesystem.getFile(f12.resolve(), fileName);
}
fileToSave.write(galleryImg);

If you want to create a subDirectory then use the following code : 如果要创建子目录,请使用以下代码:

var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mysubdir');
dir.createDirectory(); // this creates the directory

But, let me specify that the file can be save in the Application Directory only in IOS but in android you can save it in the externalStorage . 但是,让我指定该文件只能在IOS中保存在应用程序目录中,但是在android中,您可以将其保存在externalStorage中 You can have look at the documentation through the below link : 您可以通过以下链接查看文档:

https://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage https://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage

EDIT 编辑

You Could do it this way : 您可以这样:

// get the TiBlob 
var blob = img_view.toImage();

// try to save the image the image
Ti.Media.saveToPhotoGallery(blob,{
    success: function(e){
        if (callback == undefined) {
           alert('Saved image to gallery');
        } else {
           callback();
        }
    },
    error: function(e){
        alert("Error saving the image");
    }
});

Good Luck, Cheers 祝你好运,干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM