我要实现的是先从文件中读取一个BMP图象,再将其转换成灰度图,并显示出来

解决方案 »

  1.   

    //读取你的文件LPBYTE lpBits
    int i,j;
    unsigned char *temp,*temp0;
    for(i=0;i<lpbih->biHeight;i++)
    {
        for(j=0;j<lpbih->biWidth;j++)
    {
    temp=lpBits;temp0=lpBits;
        *temp0= ( 9798*(*temp) + 19235*(*temp++) +  3735*(*temp++)) / 32768;
    *lpBits=*temp;
    lpBits++;
    *lpBits=*temp;
    lpBits++;
    *lpBits=*temp;
    lpBits++;
    }
    }//再存储你得到的位图
      

  2.   

    你就不能现在坛子上找找么?这个问题已经到处都是了!Gray=0.114×Blue+0.587×Green+0.299×Red
      

  3.   

    有个简单的方法,就是把RGB颜色值统一成一个值就行了。
    通常把RGB一起付成他们3个中最大的那个。