Monacaを使用してアプリ開発を行っております。
スマホに保存されている画像をアプリ内に取り込むために、「ImagePicker」というCordovaプラグインを用いて、動いております。
http://plugins.telerik.com/cordova/plugin/imagepicker
オプションを設定することにより、例えば「width」に「400」と設定すると、400px幅にサイズ変更された画像を取得することができるのですが、サイズ変更せずに、オリジナルサイズの画像を取得したいと考えております。
このオプションを外すとファイルエラー(5)と表示され、また、別のサイトで「widthとheight双方が“0”のときオリジナルサイズを返す」とありましたので試してみたのですが、同様のエラーでした。
こちらのプラグインで、オリジナルサイズの画像を(=画像何も加工せずそのまま)取得する方法をご存知の方はいらっしゃいませんでしょうか。
よろしくお願いいたします。
追記:コードを追記します。
function getImage() { try{ window.imagePicker.getPictures( function(results) { var content = ''; for (var i = 0; i < results.length; i++) { camera_success(results[i]); // 取得成功時にファイルを保存する関数を実行 } }, function (error) { alert('Error: ' + error); }, { //maximumImagesCount: 10, //取り込める最大枚数(Androidのみ) title: '画像を選択', //message: '取り込める枚数は最大10枚までです。', width: 2000 // 高さを指定してなければ画像はこの幅を基準としたサイズにリサイズされる //quality: 100 // サイズ変更された画像の品質(デフォルト100) //outputType: imagePicker.OutputType.BASE64_STRING } ); } catch(e){ alert(e); } }
【再追記】
プラグインのJavaScriptがあったので、コードを以下に掲載いたします。
「画像のサイズを変更する幅(高さ/幅のいずれかが0の場合は、サイズに合わせてサイズが変更されます)他のアスペクト比を維持しながら、高さと幅の両方が0の場合、フルサイズイメージが返されます)」と書いてありますが、widthとheightを0にすると「FileError:5」と出て取得できません。
/*global cordova,window,console*/ /** * An Image Picker plugin for Cordova * * Developed by Wymsee for Sync OnSet */ var ImagePicker = function() { }; ImagePicker.prototype.OutputType = { FILE_URI: 0, BASE64_STRING: 1 }; ImagePicker.prototype.validateOutputType = function(options){ var outputType = options.outputType; if(outputType){ if(outputType !== this.OutputType.FILE_URI && outputType !== this.OutputType.BASE64_STRING){ console.log('Invalid output type option entered. Defaulting to FILE_URI. Please use window.imagePicker.OutputType.FILE_URI or window.imagePicker.OutputType.BASE64_STRING'); options.outputType = this.OutputType.FILE_URI; } } }; ImagePicker.prototype.hasReadPermission = function(callback) { return cordova.exec(callback, null, "ImagePicker", "hasReadPermission", []); }; ImagePicker.prototype.requestReadPermission = function(callback) { return cordova.exec(callback, null, "ImagePicker", "requestReadPermission", []); }; /* * success - success callback * fail - error callback * options * .maximumImagesCount - max images to be selected, defaults to 15. If this is set to 1, * upon selection of a single image, the plugin will return it. * .width - width to resize image to (if one of height/width is 0, will resize to fit the * other while keeping aspect ratio, if both height and width are 0, the full size * image will be returned) * .height - height to resize image to * .quality - quality of resized image, defaults to 100 * .outputType - type of output returned. defaults to file URIs. * Please see ImagePicker.OutputType for available values. */ ImagePicker.prototype.getPictures = function(success, fail, options) { if (!options) { options = {}; } this.validateOutputType(options); var params = { maximumImagesCount: options.maximumImagesCount ? options.maximumImagesCount : 15, width: options.width ? options.width : 0, height: options.height ? options.height : 0, quality: options.quality ? options.quality : 100, allow_video: options.allow_video ? options.allow_video : false, title: options.title ? options.title : 'Select an Album', // the default is the message of the old plugin impl message: options.message ? options.message : null, // the old plugin impl didn't have it, so passing null by default outputType: options.outputType ? options.outputType : this.OutputType.FILE_URI, disable_popover: options.disable_popover ? options.disable_popover : false // Disable the iOS popover as seen on iPad }; return cordova.exec(success, fail, "ImagePicker", "getPictures", [params]); }; window.imagePicker = new ImagePicker();
あなたの回答
tips
プレビュー