Answered by:
How to return var in function getImagePropertiesAsync()

Question
-
function fileDetail(image) { return image.properties.getImagePropertiesAsync().then(function (chiTiet) { var imgWidth = chiTiet.width; var imgHeight = chiTiet.height; var imgBlob = URL.createObjectURL(image, { oneTimeOnly: true }); var dataString = imgWidth + "|" + imgHeight + "|" + imgBlob + "~"; return dataString; }); }
This is not work, how i can return var dataString ?Wednesday, October 22, 2014 11:52 AM
Answers
-
To use a file picker I would do the following:
var functionThatDoesWhatYouWant = function(dataString){ //do work with data string }; var fileDetail = function (image) { return image.properties.getImagePropertiesAsync().then(function (chiTiet) { var imgWidth = chiTiet.width; var imgHeight = chiTiet.height; var imgBlob = URL.createObjectURL(image, { oneTimeOnly: true }); var dataString = imgWidth + "|" + imgHeight + "|" + imgBlob + "~"; functionThatDoesWhatYouWant(dataString); }); }; var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail; openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary; // Users expect to have a filtered view of their folders depending on the scenario. openPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]); // Open the picker for the user to pick a file openPicker.pickSingleFileAsync().then(function (file) { if (file) { // Application now has read/write access to the picked file fileDetail(file); } else { // The picker was dismissed with no selected file WinJS.log && WinJS.log("Operation cancelled.", "sample", "status"); } });
I open the picker, once the file is selected I call your function and finally, call the "functionThatDoesWhatYouWant" (replace that name with whatever suits you and put your desired code inside).
- Marked as answer by nhattuanbl Friday, October 24, 2014 3:03 AM
Thursday, October 23, 2014 3:21 PM
All replies
-
Hi!
By doing that "return" you are only returning the Promise in the chain, not the direct result.
You could invoke your function like this:
fileDetail.done(function(dataString){ //use it here });
Wednesday, October 22, 2014 6:45 PM -
Tested but it not work, i use folder picker after that get all file properties, please show me some example code please.Wednesday, October 22, 2014 7:01 PM
-
To use a file picker I would do the following:
var functionThatDoesWhatYouWant = function(dataString){ //do work with data string }; var fileDetail = function (image) { return image.properties.getImagePropertiesAsync().then(function (chiTiet) { var imgWidth = chiTiet.width; var imgHeight = chiTiet.height; var imgBlob = URL.createObjectURL(image, { oneTimeOnly: true }); var dataString = imgWidth + "|" + imgHeight + "|" + imgBlob + "~"; functionThatDoesWhatYouWant(dataString); }); }; var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail; openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary; // Users expect to have a filtered view of their folders depending on the scenario. openPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]); // Open the picker for the user to pick a file openPicker.pickSingleFileAsync().then(function (file) { if (file) { // Application now has read/write access to the picked file fileDetail(file); } else { // The picker was dismissed with no selected file WinJS.log && WinJS.log("Operation cancelled.", "sample", "status"); } });
I open the picker, once the file is selected I call your function and finally, call the "functionThatDoesWhatYouWant" (replace that name with whatever suits you and put your desired code inside).
- Marked as answer by nhattuanbl Friday, October 24, 2014 3:03 AM
Thursday, October 23, 2014 3:21 PM