【EasyX】RGB to Gray

code:

#include <graphics.h>
#include <conio.h>

void main()
{
    initgraph(1024, 768);
    // 读取图片
    loadimage(NULL, "F:\\暑期软件工程培训\\EasyXGame\\easyx_test\\easyx_test\\test.jpg");
    BeginBatchDraw();

    int c;
    for(int x=0; x<1024; x++)
    for(int y=0; y<768; y++)
    {
        c = getpixel(x, y);
        int bb = (c & 0xff0000)/256/256;
        int gg = (c&0x00ff00)/256;
        int rr = (c&0x0000ff);
        int gray = (rr*299+gg*587+bb*114+500)/1000;
        c = gray*256*256+gray*256+gray ;
        putpixel(x, y, c);
    }
    EndBatchDraw();

    getch();
    closegraph();
}

 

posted @ 2016-07-18 10:54  Hardsoftware  阅读(336)  评论(0编辑  收藏  举报