uwp - UWP - 调整大小后元数据中的图像大小未更改
问题描述
我设法在 UWP 应用程序中调整了图片的大小,当我打开图像时它的大小正确,但问题是图像元数据仍然显示原始图像大小值。
图像元数据是否必须在某些时候更改?
非常感谢您的帮助!
这是我正在使用的代码:
private async Task ResizeFile(StorageFile resizedFile, StorageFile sourceFile, int width, int height)
{
var imageStream = await sourceFile.OpenReadAsync();
var decoder = await BitmapDecoder.CreateAsync(imageStream);
// get original picture size
int originalWidth = (int)decoder.PixelWidth;
int originalHeight = (int)decoder.PixelHeight;
// calculate aspect ratio
var ratioX = (float)width / (float)originalWidth;
var ratioY = (float)height / (float)originalHeight;
int newWidth = width;
int newHeight = height;
var ratio = Math.Min(ratioX, ratioY);
if (ratio != 0)
{
newHeight = (int)(originalHeight * ratio);
newWidth = (int)(originalWidth * ratio);
}
using (var resizedStream = await resizedFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateForTranscodingAsync(resizedStream, decoder);
encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Linear;
encoder.BitmapTransform.ScaledHeight = (uint)newHeight;
encoder.BitmapTransform.ScaledWidth = (uint)newWidth;
await encoder.FlushAsync();
}
}
解决方案
推荐阅读
- javascript - Ember.js - 扩展 Bootstrap 插件的功能
- reactjs - 在 ReactJS 中,我可以“复制” Draggable 项目,以便拖动克隆并且原始项目保持在同一个地方吗?
- python - 如何获取 Kafka-python 消费者端最后 'n' 分钟内的数据(消息)
- css - 在 CSS 中创建钻石形状和里面的内容
- javascript - 调用操作的 XSS 风险 $.ajax(options)
- javascript - 不需要字段时自动聚焦在每个文本框上
- c - 可以将 HANDLE 类型的变量与 C 中的 NULL 进行比较?
- python - 如何使用 python 在另一个列表中找到一个列表?
- php - 流明如何将变量传递给通知
- python - 我无法在 aws 批处理作业中传递参数?