LoginSignup
1
0

More than 5 years have passed since last update.

PhotoGalleryの写真を新規ファイルとしてアプリ内に保存する

Last updated at Posted at 2012-03-16

PhotoGalleryから写真選択してアプリ内に新規ファイルとして保存するのに少しハマりました。
指定したファイルが存在しなかった場合createFileをしないといけなかったんですね。それだけです。

未確認ですがカメラなどのMediaでも同様だと思います。

mediaNewFileSave.js
Titanium.Media.openPhotoGallery({
    success: function(event) {          
        // アプリケーションデータディレクトリに出力する。
        var f = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory + "/" + 'name.png');
        if (!f.exists()) {
            f.createFile();
        }
        f.write(event.media);
    },
    error: function(error) {
        // notify(e.message);
    },
    cancel: function() {
        // キャンセル時の挙動
    },
    // 撮影データのフォトギャラリーへの保存
    saveToPhotoGallery:true,
    // 選択直後に拡大縮小移動をするか否かのフラグ
    allowEditing: true,
    // 選択可能なメディア種別を配列で指定
    mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0