调整图像大小并保留元数据/属性项

时间:2009-06-26 19:51:22

标签: .net image metadata

.NET库在调整看起来很棒的图像方面表现非常出色:

Bitmap newImage = new Bitmap(newWidth, newHeight);
using (Graphics gr = Graphics.FromImage(newImage))
{
    gr.InterpolationMode = InterpolationMode.HighQualityBilinear;
    gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));
}

我在网上看到的解决方案中遇到的一个问题是,它们会删除嵌入在这些图像中的元数据。有没有办法将这些数据传输到新图像?或者使用原始图像并保留这些数据?

理想情况下,如果可能,我还希望仅使用Microsoft内置的.NET库来保留此解决方案。

1 个答案:

答案 0 :(得分:3)

迭代Image.PropertyItems中的所有property items并将它们添加到新图像中。您可以使用此方法here找到如何复制元数据的示例。