Quick Question

Posts 1–6 of 6 · Page 1 of 1
Quick Question
Code:
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
int main()
{
	POINT p;
	HDC hdc;
	COLORREF rgb;
	string log;
	
	int r,g,b;
	while(true)
	{
		GetCursorPos(&p);
		hdc = GetDC(0);
		rgb = GetPixel(hdc,p.x,p.y);
		r = GetRValue(rgb);
		g = GetGValue(rgb);
		b = GetBValue(rgb);
		if(GetAsyncKeyState(VK_INSERT)&1){cout<<r<<" "<<g<<" "<<b<<"\n"; log += "r == "; log += r; log +=" &&"; log+=" g == "; log+=g; log+=" && b == "; log+= b; log+="\n";}
		if(GetAsyncKeyState(VK_DELETE)&1){system("cls");}
		Sleep(2);
		ofstream myfile;
		myfile.open ("rgb.txt");
		myfile << log;
		

	}
}
The problem i am having is that it won't actually write the value of r,g,or b. It will give me a funny looking character. I understand why(cuz it's an int variable not a string, hence the printing error)but i just want to know how i could make it print the actual number. I thought of a way and here it is:
Code:
if(r == 1){
string one = "1";
}
and so on...
obviously it is a bad idea because you would have to right 255 if statements. You could also do the same with switch statements, but i just want a way that's easier. Thank you, your help is much appreciated.
Code:
cout << GetRValue(rgb);
you can try this. I don't know if it works haven't coded in a while and didn't try it
char str[32];
sprintf(str, "%d", GetRValue(color));
i want it to write r's value to a text file, i already know how to make it input the # to console.
Quote Originally Posted by 258456 View Post
i want it to write r's value to a text file, i already know how to make it input the # to console.
What HD posted writes the decimal value of the R value to 'str', from there just output that into your text file.
oh, thanks void, and thanks HD, sorry i didn't understand
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us