我是菜鸟,刚接触VC++不久,现有问题一个,望各位大侠帮忙我的问题:我用API函数LoadImage返回了一个HBITMAP,现在我如何将该HBITMAP对象转换成字符缓冲区unsigned char*呢?
不要先写磁盘再转换,而是直接在内存中完成,谢谢各位啦!

解决方案 »

  1.   

    可以用GetDIBits。不过,你直接打开文件来读多好。
      

  2.   

    GetDIBits能得到位图的数据区.
    如果你是想把一张位图通过网络传输出去,最好压缩处理下..
      

  3.   

    用 ifstream 从文件中 读取数据是最简洁的,当然也可用 CFile.既然非要从句柄开始就只能
    GetDIBits
    The GetDIBits function retrieves the bits of the specified compatible bitmap and copies them into a buffer as a DIB using the specified format. int GetDIBits(
      HDC hdc,           // handle to DC
      HBITMAP hbmp,      // handle to bitmap
      UINT uStartScan,   // first scan line to set
      UINT cScanLines,   // number of scan lines to copy
      LPVOID lpvBits,    // array for bitmap bits
      LPBITMAPINFO lpbi, // bitmap data buffer
      UINT uUsage        // RGB or palette index
    );
    PS:如果是为了 显示 图像,直接StretchDIBits就好了,呵呵