[英]Why does WebImage.Resize strip out PNG transparency
Using WebImage from the MVC3/WebMatrix release. 使用MVC3 / WebMatrix版本中的WebImage 。 Loading the following image from a file path:
从文件路径加载以下图像:
- or -
- 要么 -
Running the following code against it: 针对它运行以下代码:
return new WebImage(path)
.Resize(120, 265)
.GetBytes("Png");
Results in an image with the transparency stripped out and black used in place: 在透明度被剥离并且使用黑色的图像中的结果:
The same happens with RotateRight(), RotateLeft() and FlipHorizantal() However if I don't call the .Resize() method: RotateRight(),RotateLeft()和FlipHorizantal()也是如此。但是,如果我不调用.Resize()方法:
return new WebImage(path)
.GetBytes("Png");
The image is returned without an issue. 图像返回没有问题。
Is your image 8-bit (indexed color)? 你的图像是8位(索引颜色)? When 8-bit images are resized, they are often converted from indexed color to RGB in order to make the result look smoother.
调整8位图像的大小时,它们通常会从索引颜色转换为RGB,以使结果看起来更平滑。 Resizing images without changing the color table rarely ends well.
在不更改颜色表的情况下调整图像大小很少结束。
If the image is already RGB (24-bit or more), it's a little more complex: What should the resizer do for the edges of an image, on the border between "transparent" and "not transparent"? 如果图像已经是RGB(24位或更多),那就有点复杂了:在“透明”和“不透明”之间的边界上,缩放器应该对图像的边缘做什么? Many resizing algorithms will do something resembling "averaging the two colors" at a border (again, to make the image look smoother), but most have no concept of transparency, let alone PNG's ability to have multiple levels of translucency.
许多调整大小算法将在边界处执行类似于“平均两种颜色”的操作(同样,为了使图像看起来更平滑),但大多数没有透明度的概念,更不用说PNG具有多层次半透明的能力。
So, the short answer is "it's probably a bug" -- not a full implementation of PNG's features. 所以,简短的回答是“它可能是一个错误” - 而不是PNG功能的完整实现。
The solution may not exist, but I'd try: 解决方案可能不存在,但我会尝试:
您是否尝试使用方法Write()
而不是GetBytes()
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.