Settings | Sign in | Sign up

The author has 3 posts.

【程序】自己写的RGB格式的颜色转换成十六进制表示的颜色的转换器

Floor 1 巨大八爪鱼 11/10/15 13:31
// ColorRGB.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned char red, green, blue;
    while (1)
    {
        printf("Please input the three RGB values: \n");
        scanf_s("%d%d%d", &red, &green, &blue);
        printf("The result is: #%02X%02X%02X\n\n", red, green, blue);
    }
    return 0;
}

Floor 2 巨大八爪鱼 11/10/15 13:32
运行效果:
Floor 3 巨大八爪鱼 11/10/15 13:38
上述程序在编译成Release版本后无法读取第二个green的颜色值,所以最好把unsigned char改成unsigned int:
// ColorRGB.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned int red, green, blue;
    while (1)
    {
        printf("Please input the three RGB values: \n");
        scanf_s("%d%d%d", &red, &green, &blue);
        printf("The result is: #%02X%02X%02X\n\n", red, green, blue);
    }
    return 0;
}


Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.