c# libpng warning: iCCP: known incorrect sRGB profile
时间: 2023-11-12 19:59:39 浏览: 37
这个警告通常是由于 PNG 图像中包含了不正确的 ICC 颜色配置文件导致的。这个问题可以通过使用 libpng 库的 png_set_strip_16() 函数来解决,该函数可以将图像中的 16 位样本值转换为 8 位样本值,并删除 ICC 颜色配置文件。以下是一个示例代码:
```csharp
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
class Program
{
static void Main(string[] args)
{
string inputPath = "input.png";
string outputPath = "output.png";
using (var inputStream = File.OpenRead(inputPath))
using (var outputStream = File.Create(outputPath))
using (var image = Image.FromStream(inputStream))
{
var pngEncoder = ImageCodecInfo.GetImageEncoders()
.First(codec => codec.FormatID == ImageFormat.Png.Guid);
var encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(
Encoder.ColorDepth, 8L);
var bitmap = new Bitmap(image);
bitmap.Save(outputStream, pngEncoder, encoderParameters);
}
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)