0

我正在尝试从 Win 8 应用程序中的图片中获取大小(像素、咬痕)。我用 openPicker 选择文件并得到文件。但是我找不到尺寸属性?如果文件太大,我会显示错误。知道如何获取此信息吗?谢谢。

4

2 回答 2

0

经过几个小时的搜索和尝试,我已经解决了这个问题:

//add picture
        document.getElementById("btnAddImg").addEventListener('click', function () {
            // Create the picker object and set options
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
            openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
            openPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
             openPicker.pickSingleFileAsync().then(function (file) {
                file.openAsync(Windows.Storage.FileAccessMode.read).done(function (stream) {
                    var fileType = file.contentType;
                    var blob = MSApp.createBlobFromRandomAccessStream(fileType, stream);
                    var fdata = new FormData();
                    fdata.append('upload_field', blob);
                    //more code....
                });
             });
        });

希望它对其他人有所帮助。

于 2013-11-08T16:03:59.030 回答
0

您可以通过 StorageFile 对象本身获取此信息,而无需打开文件或将其加载到内存中。

为方便起见,假设 myFile 是有问题的 StorageFile。

对于图像尺寸,调用myFile.properties.getImagePropertiesAsync,结果是一个包含宽度和高度属性的ImageProperties对象。您可以在场景 1的简单成像示例中找到检索 ImageProperties 的示例。

对于文件大小,请调用myFile.getBasicPropertiesAsync。结果是一个BasicProperties对象,其 size 属性具有该值。

于 2013-11-08T17:56:27.260 回答