0
我试图将图像文件复制到本地存储并调整大小(以便在活动图块中显示它)。我主要是在这里修补,这是我的第一个Windows应用商店应用程序和所有。到目前为止,这是我:在Windows应用商店应用中调整图像大小
var fileStream = null;
currentPhoto.copyAsync(Windows.Storage.ApplicationData.current.localFolder, currentPhoto.name)
.then(function (file) {
return file.openAsync(Windows.Storage.FileAccessMode.readWrite);
})
.then(function (stream) {
return Windows.Graphics.Imaging.BitmapDecoder.createAsync(stream);
})
.then(function (decoder) {
fileStream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
return Windows.Graphics.Imaging.BitmapEncoder.createForTranscodingAsync(fileStream, decoder);
})
.then(function (encoder) {
encoder.bitmapTransform.scaledWidth = 100;
encoder.bitmapTransform.scaledHeight = 100;
return encoder.flushAsync();
})
.then(function() {
fileStream.close();
})
.done(function() {
// do tile update
});
我会计算一个合适的宽高比后,我得到这个角色的工作,现在是100×100精细的测试。调试时我注意到编码器正在检测到它是一个JPG文件。但是,如果我插入到函数链中调用读取已保存到本地存储的文件,那么我看到它没有被调整大小。所以,自然而然,活动磁贴更新会忽略它,因为它太大。
我在尝试调整图像大小时错过了一个步骤吗?或者也许有更简单的方法来实现这一点?