c# - 在 C# 中使用 ImageAttributes 旋转色调

标签 c# .net image gdi+ colormatrix

如何使用 GDI+ 的 ImageAttributes(可能还有 ColorMatrix)旋转图像的色调?

请注意,我想旋转色调,而不是给图像着色。

编辑:通过旋转色调,我的意思是图像中的每种颜色都应该转变为不同的颜色,而不是使整个图像成为一种颜色的阴影。

例如,

原文:http://www.codeguru.com/img/legacy/gdi/Tinter03.jpg

旋转:http://www.codeguru.com/img/legacy/gdi/Tinter15.jpghttp://www.codeguru.com/img/legacy/gdi/Tinter17.jpg

最佳答案

I threw this together对于这个问题(帖子底部链接的带有 c# 项目的 ZIP 文件)。它不使用 ImageAttributesColorMatrix,但它会按照您所描述的那样旋转色调:

//rotate hue for a pixel
private Color CalculateHueChange(Color oldColor, float hue)
{
    HLSRGB color = new HLSRGB(
        Convert.ToByte(oldColor.R),
        Convert.ToByte(oldColor.G),
        Convert.ToByte(oldColor.B));

    float startHue = color.Hue;
    color.Hue = startHue + hue;
    return color.Color;
}

关于c# - 在 C# 中使用 ImageAttributes 旋转色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1079820/

相关文章:

c# - 获取 ProjectItem 的命名空间

.net - Azure 服务总线主题中的基础 IOException

c# - .NET compact framework - 将文件放在哪里以便模拟器可以访问它们

image - 如何使用 PyGI 在 Python3 中自动调整图像大小?

iOS Cocos2D优化

c# - MVC 2 需要什么版本的 .net?

c# - 如何在 UWP 中获取单播、Dns 和网关地址?

c# - 为什么协变和逆变不支持值类型

在 flutter 中使用 image.asset 时,图像质量会下降

c# - "Execution of the ' document() ' function was prohibited."其中 EnableDocumentFunction 设置为 true?