如何在程序中画出这个光谱?

uoyevoli 2007-05-29 10:25:54
http://lh5.google.com/image/farproc/RluNiEoxQ4I/AAAAAAAAAlo/fUUEJfmGq_s/s144/RGB24-spectrum.jpg

1、使用Windows API画出这个图像。不是先保存一个图片,然后贴到DC上。
2、给出光谱上的某点坐标,算出(不是从屏幕上取出)该点的颜色值(RGB)
...全文
354 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
uoyevoli 2007-06-02
  • 打赏
  • 举报
回复
Chiyer(星羽) 你好!

感谢你的回复和帮助,但是你的程序并没有完全实现我的要求。

请您把我顶楼的图片下载到本地,打开,放大一些看,可能会更清楚地看到和您的程序实现的效果的差别。
星羽 2007-06-02
  • 打赏
  • 举报
回复
我知道,因为你那个图片看有种突起来的感觉,是因为它在纵向的亮度分布

不是平均的,我给你那个是平均的,所以没有任何凸的感觉

你可以在纵向那里的亮度做2次衰减,就可以了
uoyevoli 2007-05-30
  • 打赏
  • 举报
回复
嗯。看看。如果可以的话,两个板块都给你分。
uoyevoli 2007-05-29
  • 打赏
  • 举报
回复
谢谢楼上回复。
星羽 2007-05-29
  • 打赏
  • 举报
回复
这个是 HSI 的光普

等等中午有空帮你写个

星羽 2007-05-29
  • 打赏
  • 举报
回复
:) 我运行成功的哦,效果图跟你的一样
星羽 2007-05-29
  • 打赏
  • 举报
回复
是了,可不可是把分给到我的c++版块里咯 = =!

// ColorPick.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "ColorPick.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_COLORPICK, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_COLORPICK));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_COLORPICK));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_COLORPICK);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//

#include "math.h"

HBITMAP hBitMap = NULL;

DWORD HSV2RGB(float h, float s, float v)
{
DWORD dwRGB = 0x00000000;
float r , g , b;
float i, f, p, q, t;
r = g = b = 0.0f;

if ( s == 0.0f )
{
if ( v != 0.0f )
{
DWORD channel = static_cast<DWORD>(v * 255);
dwRGB = channel << 16 | channel << 8 | channel;
}
}
else
{
if ( h == 360.0f )
{
h = 0.0f;
}

h /= 60.0f;
i = floor(h);
f = h - i;
p = v * ( 1.0f - s );
q = v * ( 1.0f - ( s * f ) );
t = v * ( 1.0f - ( s * ( 1.0f - f) ) );

if ( i == 0.0f )
{
r = v;
g = t;
b = p;
}
else if ( i == 1.0f )
{
r = q;
g = v;
b = p;
}
else if ( i == 2.0f )
{
r = p;
g = v;
b = t;
}
else if ( i == 3.0f )
{
r = p;
g = q;
b = v;
}
else if ( i == 4.0f )
{
r = t;
g = p;
b = v;
}
else if ( i == 5.0f )
{
r = v;
g = p;
b = q;
}
dwRGB = RGB(static_cast<DWORD>(r * 255), static_cast<DWORD>(g * 255), static_cast<DWORD>(b * 255));

}
return dwRGB;
}

void DrawHSIRect(HDC hDc, RECT& Rect)
{
float fStep;
int i;

fStep = 360.0f / 255.0f;
for ( i = 0; i < 256; i++ )
{
for (int t = Rect.top; t < Rect.bottom; t++)
::SetPixel(hDc, Rect.left + i, t, HSV2RGB(fStep * i, 1.0f, 1.0f));
}


}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
{
RECT Rect = {10, 10, 255, 30};
DrawHSIRect(hdc, Rect);
}
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧