小弟写的程序有点问题,想请教各位大虾。

解决方案 »

  1.   

    gray=BYTE(0.299*red)+BYTE(0.587*green)+BYTE(0.114*blue);
    这个是转换函数.
    只要你能够正确显示BMP位图,转换是很简单的.
      

  2.   

    自己建调色版,
    1.对图片中的所有颜色做亮度和饱和度分析排序,按人眼的敏感度将前256种放到调色版。
    2.扫描所有像素点的值,把它们的24BIT或32BIT颜色值换成8BIT的调色版索引。(如果调色版中不存在着种颜色,就找最相近的替换)。
      

  3.   

    试试这个//============================================================================= CImage m_image;
    if (!m_image.IsIndexed()) { // the image does not use an indexed palette, so we will change each pixel to B&W (slow)
    COLORREF pixel;
    int maxY = m_image.GetHeight(), maxX = m_image.GetWidth();
    byte r,g,b,avg;
    for (int x=0; x<maxX; x++) {
    for (int y=0; y<maxY; y++) {
    pixel = m_image.GetPixel(x,y);
    r = GetRValue(pixel);
    g = GetGValue(pixel);
    b = GetBValue(pixel);
    avg = ((r + g + b)/3);
    m_image.SetPixelRGB(x,y,avg,avg,avg);
    }
    } } else { // the image uses an indexed palette, so we will just change the palette table entries to
    // their B&W equivalents 
    int MaxColors = m_image.GetMaxColorTableEntries();
    RGBQUAD* ColorTable;
    ColorTable = new RGBQUAD[MaxColors]; m_image.GetColorTable(0,MaxColors,ColorTable);
    for (int i=0; i<MaxColors; i++)
    {
    int avg = (ColorTable[i].rgbBlue + ColorTable[i].rgbGreen + ColorTable[i].rgbRed)/3;
    ColorTable[i].rgbBlue = (BYTE)avg;
    ColorTable[i].rgbGreen = (BYTE)avg;
    ColorTable[i].rgbRed = (BYTE)avg;
    }
    m_image.SetColorTable(0,MaxColors,ColorTable);//=============================================================================
      

  4.   

    void CTruecolorto8bitView::OnM8bitcolor()//将24位真彩色图象转换为8位256色图象 
    {
    // TODO: Add your command handler code here
    //加载位图文件
    BITMAPFILEHEADER bf;
    BITMAPINFO *binfoin,*binfoout;
    //创建两个信息头
    CFile file;
    if(!file.Open(str,CFile::modeRead,NULL)) return; binfoin=(BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+10);
    binfoout=(BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+10);
    file.Read(&bf,sizeof(BITMAPFILEHEADER));
    file.Read(binfoin,sizeof(BITMAPINFOHEADER));
    int nline=((binfoin->bmiHeader.biWidth* binfoin->bmiHeader.biBitCount+31)/8) /4*4;
    int nsize=nline*(binfoin->bmiHeader.biHeight);
    int nline8=((binfoin->bmiHeader.biWidth* 8+31)/8) /4*4;
    int nsize8=nline8*(binfoin->bmiHeader.biHeight);
    unsigned char *pdata,*pdata8;
    //为源数据开辟缓冲区
    pdata=(unsigned char *)malloc(nsize+nline+10);//注意这里必须申请一块大一点的空间,不然会益处
    //为目标数据开辟缓冲区
    pdata8=(unsigned char *)malloc(nsize8+10);
    file.Read(pdata,nsize);
    file.Close();
    //调用dll库中的函数 HINSTANCE hinstLib; 
        MYPROC ProcAdd; 
        hinstLib = LoadLibrary("demcolordll1"); 
        if (hinstLib != NULL) 
        { 
            ProcAdd = (MYPROC) GetProcAddress(hinstLib, "RGB2256HiQuality"); 
            if(ProcAdd !=NULL) 
    {
    ProcAdd(binfoin,pdata,binfoout,pdata8);
    FreeLibrary(hinstLib); 
    //将得到的数据写进文件中
    if(file.Open("temp.bmp",CFile::modeCreate|CFile::modeWrite,NULL))
    {
    bf.bfOffBits=bf.bfOffBits+1024;
    bf.bfSize=bf.bfOffBits+nsize8;
    file.Write(&bf,sizeof(BITMAPFILEHEADER));
    file.Write(binfoout,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256);
    file.Write(pdata8,nsize8);
    file.Close();
    }
    }
    }
    free(binfoin);
    free(binfoout);
    free(pdata);
    free(pdata8);
    HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,"temp.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    // CDC tempDC;
    if(hBitmap==NULL) return;
    bitmap.DeleteObject();
    bitmap.Attach(hBitmap);
    bitmap.GetObject(sizeof(BITMAP),&bm);
    bShow=true;
    Invalidate();

    }
      

  5.   

    对亚,对数组进行操作,转换颜色空间。RGB-->HSV然后提出V分量,就是灰度图了。
      

  6.   


    小土的做法正确。灰度图与RGB关系为:Lightness = ( R + G + B ) / 3;
      

  7.   

    你好,我现在也在做灰度图像的处理程序,能交流交流吗?
    我是用读取位数据,在变化为灰度位数据,通过屏幕打点的方式显示。
    我现在想通过直接对位图本身进行处理,包括8位和24位的,在思路上还很模糊
    你能说说你是怎么做的吗?
    [email protected]
    QQ:117220198
      

  8.   

    我这有代码 [email protected]
      

  9.   

    Lightness = ( R + G + B ) / 3;的做法不太正确,
    正确的公式为
    *Lightness =(int)(.299 * (double)(*pRed) + .587 * (double)(*pGrn) + .114 * (double)(*pBlu));
      

  10.   

    帮我看看这个关于图片处理的问题
    多谢http://www.5ivb.net/club/dispbbs.asp?boardID=1&ID=22563