我正在尝试使用 WinRT 将现有图像缩放到其大小的 50%。它将图像复制到本地文件夹,但不改变其大小;
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.copyAsync(Windows.Storage.ApplicationData.current.localFolder, file.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 = 50;
encoder.bitmapTransform.scaledHeight = 50;
return encoder.flushAsync();
})
.then(function () {
fileStream.close();
})
.done(function () {
// use image in the program
});
});