如何在 .NET 中调整具有透明度的图像(GIF 和 PNG)的大小,并保留透明度信息
我发现了很多关于在 .NET 中调整图像大小的问题以及诸如此类的问题,但他们似乎都没有谈论调整具有透明度的图像大小(包括像 GIF 这样的 1 位和像 PNG 这样的带有 alpha 通道的图像),显然是在试图保持透明度。
也许 GDI/GDI+ 有点缺乏代码来轻松管理这些场景或者其他什么?如果无法按原样使用 .NET,您是否知道有任何库可以做到这一点,即使不是免费的。我只是不希望它成为一个命令行工具(否则 ImageMagick 可能很容易做到这一点),以实现更好的集成和自动化目的。
谢谢你们。哦,还有女孩们。
i found a lot of questions about resizing images in .NET and whatnot, but none of them seemed to talk about resizing images that have transparency (both 1bit like GIFs and w/ alpha channel like PNGs), trying obviously to keep that transparency.
Maybe GDI/GDI+ is somewhat lacking of code to easily manage those scenarios or what else? If it's not possible to use .NET as it is, are you aware of any library that can do that, even not free. I just wouldn't like it to be a command line tool (otherwise ImageMagick would probably do the trick easily) for better integration and automation purposes.
Thanks guys. Oh, and gals too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上就是您要问的 为什么调整 png 图像大小会失去透明度?
This is effectively what you are asking Why does resizing a png image lose transparency?
http://imageresizing.net 库在 GIF 和 PNG 格式之间转换时保留透明度。它是开源的,因此您可以参考源代码来了解如何实现它。我相信调色板生成是保持透明度的关键,但自从我上次对 GIF 和 PNG 量化代码进行更改以来已经有一段时间了 - 它已经稳定了好几年。
The http://imageresizing.net library preserves transparency when converting between GIF and PNG formats. It's open-source, so you can refer to the source code to see how to achieve it. I believe that the palette generation is key in maintaining transparency, but it's been a while since I made the last change to the GIF and PNG quanitization code - it's been stable for several years.