本文介绍了C ++如何使用setpixel函数将色调曲线(gamma)绘制到图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所提到的。我试图画一个伽马色调曲线,但我不知道该怎么做。我可以做线性色调曲线很好,但是当谈到绘制伽玛色调曲线,我完全失去它。如(第1张或第2张图)

As title mentions. I'm trying to draw a gamma tone curve but i do not have any idea how to do it. I can do linear tone curve just fine, but when it comes to drawing gamma tone curve, i totally just lose it. As referenced from http://www.mediachance.com/pseam/help/curves.html (1st or 2nd drawing)

代码如下

#include <math.h>

static COLORREF red=RGB(255,0,0);
static COLORREF blue=RGB(0,0,255);
static COLORREF green=RGB(0,255,0);

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

The part where i should incorporate in to draw the gamma tone curve

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) 。然后只需从上一个点到当前点绘制一条线。

Drawing a graph should be simple. For each X point you have, calculate the corresponding Y value - in the case of Gamma on a scale of 0-255 that will be y = round(pow(x/255., gamma)*255). Then just draw a line from the previous point to the current point.

这篇关于C ++如何使用setpixel函数将色调曲线(gamma)绘制到图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 04:51