实在没时间去研究BMP的结构。
    求一程序
    对BMP的元素集合。
    结果以数组的方式保存在文件中。谢谢

解决方案 »

  1.   

    你的意思是去掉BMP图像的文件头和信息头之类,只保存裸图像数据么?
      

  2.   

    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;
       HDC hdc;
       HDC bufdc;
       BITMAP bm1,bm2;
       HBITMAP bm;
    unsigned char *p1,*p2;   hInst = hInstance; // Store instance handle in our global variable   hWnd = CreateWindow("lid", "", WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);   if (!hWnd)
       {
          return FALSE;
       } MoveWindow(hWnd,50,30,600,450,true);
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);   hdc = GetDC(hWnd);
    mdc = ::CreateCompatibleDC(hdc);
    bufdc = ::CreateCompatibleDC(hdc);
    girl = ::CreateCompatibleBitmap(hdc,298,329); bg = (HBITMAP)(::LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,600,450,LR_LOADFROMFILE));
    bm = (HBITMAP)(::LoadImage(NULL,"girl.bmp",IMAGE_BITMAP,596,329,LR_LOADFROMFILE)); SelectObject(mdc,girl);

    SelectObject(bufdc,bg);
    BitBlt(mdc,0,0,298,329,bufdc,xstart,ystart,SRCCOPY);
    SelectObject(bufdc,bm);
    BitBlt(mdc,0,0,298,329,bufdc,298,0,SRCAND);
    BitBlt(mdc,0,0,298,329,bufdc,0,0,SRCPAINT); ::GetObject(bg,sizeof(BITMAP),&bm1);
    ::GetObject(girl,sizeof(BITMAP),&bm2); p1 = new unsigned char [bm1.bmHeight*bm1.bmWidthBytes];
    p2 = new unsigned char [bm2.bmHeight*bm1.bmWidthBytes]; ::GetBitmapBits(bg,bm1.bmHeight*bm1.bmWidthBytes,p1);
    ::GetBitmapBits(girl,bm2.bmHeight*bm2.bmWidthBytes,p2); int xend = xstart +298;
    int yend = ystart +329;
    int pixel = bm1.bmBitsPixel/8;
    int index;
    int x;
    int y;
    int i;

    for(y=ystart; y<yend; y++)
    {
    for(x=xstart; x<xend; x++)
    {
    index = y * bm1.bmWidthBytes + x * pixel;
    p1[index]   = p1[index]   * 0.8;
    p1[index+1] = p1[index+1] * 0.8;
    p1[index+2] = p1[index+2] * 0.8;
    }
    } for(y=0; y<329; y++)
    {
    for(x=0; x<298; x++)
    {
    index = y * bm2.bmWidthBytes + x * pixel;
    i = (y+ystart) * bm1.bmWidthBytes + (x+xstart) * pixel;
    p2[index]   = p2[index]   * 0.2 + p1[i];
    p2[index+1] = p2[index+1] * 0.2 + p1[i+1];
    p2[index+2] = p2[index+2] * 0.2 + p1[i+2];
    }
    } ::SetBitmapBits(girl,bm2.bmHeight*bm2.bmWidthBytes,p2); MyPaint(hdc);
    delete []p1;
    delete []p2;   return TRUE;
    }
      

  3.   

    文件移动sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)
    如果8色以下,还要加上BITMAPINFOHEADER中的biClrUsed*4