C++如何使用setpixel函数绘制色调曲线(gamma)到图形

C++ how to draw a tone curve (gamma) to graph using setpixel function

本文关键字:gamma 图形 曲线 色调 何使用 setpixel 函数 绘制 C++      更新时间:2023-10-16

如标题所述。我正试图画一条伽马色调曲线,但我不知道如何做。我可以画线性色调曲线,但是当涉及到绘制伽马色调曲线时,我完全失去了它http://www.mediachance.com/pseam/help/curves.html(第1张或第2张图纸)

代码如下

#include <math.h>
static COLORREF red=RGB(255,0,0);
static COLORREF blue=RGB(0,0,255);
static COLORREF green=RGB(0,255,0);

我应该结合在其中绘制伽马色调曲线的部分

for(int y=0; y<bih.biHeight; y++)
            {                       
                for(int x=0; x<bih.biWidth; x++)
                {   
                SetPixel(hdc, x, bih.biHeight-x, red);
}
// The X axis of the graph
HPEN hLinePen1;
                COLORREF qLineColor1;
                qLineColor1 = RGB(255, 0, 0);
                hLinePen1 = CreatePen(PS_SOLID, 2, qLineColor1);
                hPenOld1 = (HPEN)SelectObject(hdc, hLinePen1);
                line(hdc,0, bih.biHeight, bih.biWidth, bih.biHeight);
                SelectObject(hdc, hPenOld1);
                DeleteObject(hLinePen1);
// The Y axis of the graph
                HPEN hLinePen2;
                COLORREF qLineColor2;
                qLineColor2 = RGB(255, 0, 0);
                hLinePen2 = CreatePen(PS_SOLID, 2, qLineColor2);
                hPenOld2 = (HPEN)SelectObject(hdc, hLinePen2);
                line(hdc,0, bih.biHeight, 0, bih.biWidth-bih.biHeight);
                SelectObject(hdc, hPenOld2);
                DeleteObject(hLinePen2);

绘制图形应该很简单。对于您拥有的每个X点,计算相应的Y值-在Gamma的情况下,范围为0-255,即y = round(pow(x/255., gamma)*255)。然后从上一个点到当前点画一条线。