请求支援

解决方案 »

  1.   


    #include "atlimage.h"/**
    * 24位位图文件转换为16位位图文件
    * char* filename: 24位位图文件路径 如果是内存中的数据用IStream*
    * char *destfilename:转换后保存的16位位图文件路径,如果要转换到内存中用IStream*
    */
    bool ConvertBmp( char* filename,char *destfilename )
    {
    /**
    * 使用CImage类装载图像, 并且转换为位图
    */ CImage img;
    HRESULT hr = img.Load( filename );
    if( FAILED( hr ) )
    {
    return false;
    } /**
    * 确定目标位图的尺寸
    */
    int width = img.GetWidth();
    int height = img.GetHeight();
    /**
    * 创建内存DC
    */ 
    HDC hdc = ::CreateCompatibleDC( NULL ); /**
    * 使用DIBSection装载位图
    */
    BITMAPINFO * info = (BITMAPINFO *)malloc( sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256 );
    memset(info, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256 );
    info->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
    info->bmiHeader.biWidth = width;
    info->bmiHeader.biHeight = height;
    info->bmiHeader.biPlanes = 1;
    info->bmiHeader.biBitCount = 16 ;
    info->bmiHeader.biCompression = BI_RGB;
    info->bmiHeader.biClrUsed = 0;
    info->bmiHeader.biClrImportant = 0;
    void * bits = NULL; HBITMAP hbmp = CreateDIBSection(
    hdc, 
    info,
    DIB_RGB_COLORS,
    &bits,
    NULL,
    0); free(info);
    if(!hbmp)
    {
    DeleteDC( hdc );
    return NULL;
    }
    SelectObject( hdc, hbmp ); /**
    * 将CImage类装载的图像内容绘制在hdc上
    */
    img.Draw(
    hdc,
    0,
    0,
    width,
    height );
    DeleteObject( img.Detach() );
    img.Attach( hbmp );
    img.Save( destfilename ); DeleteObject( hbmp );
    DeleteDC( hdc );
    return true;
    }
      

  2.   

    #include "atlimage.h"???
     fatal error C1083: Cannot open include file: 'atlimage.h': No such file or directory
    Error executing cl.exe.
    我编译就出现这个错误的。
      

  3.   

    atlimage.h在E:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include下
    用.net2003.不要用vc6.0
      

  4.   

    自己装个.net2003后把此代码拷贝出来就可以用了。