使用 WIC 重现 WPF BitmapImage.DecodePixelWidth / 高度

Using WIC to reproduce WPF BitmapImage.DecodePixelWidth / Height

我需要生成 "huge" 个图像文件的缩略图,而不需要将完整图像加载到内存中。 此功能在 WPF 的 BitmapImage.DecodePixelWidth / Height 中完美实现,但我需要在非托管 C++ dll 中使用它。

我 "think" 它是使用 WIC 实现的,但是我找不到任何关于此功能的有用示例,我会加载 WIC 可以处理的所有缩略图格式。

有人可以帮忙吗?

两个 WIC 编解码器 (JPEG and JPEG-XR) support scaling within the decoder, and you can verify this at runtime using IWICBitmapSourceTransform::GetClosestSize. However, even if the source image must be decoded at its full resolution, IWICBitmapScaler will use minimal memory when scaling the image to its desired size, as indicated in the documentation's remarks.

更好的是,IWICBitmapScaler 将在支持时自动使用解码器的 IWICBitmapSourceTransform 功能,因此您只需使用它并自动获得您寻求的行为。