请教:
BOOL CCaptureVideo::SaveBitmap(BYTE * pBuffer, long lBufferSize )
   {
  HANDLE hf = CreateFile(
  m_szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,
  CREATE_ALWAYS, NULL, NULL );
  if( hf == INVALID_HANDLE_VALUE ) return 0;
    // 写文件头 
    BITMAPFILEHEADER bfh;
    memset( &bfh, 0, sizeof( bfh ) );
    bfh.bfType = 'MB';
    bfh.bfSize = sizeof( bfh ) + lBufferSize + sizeof( BITMAPINFOHEADER );
    bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );
    DWORD dwWritten = 0;
    WriteFile( hf, &bfh, sizeof( bfh ), &dwWritten, NULL );
    // 写位图格式
    BITMAPINFOHEADER bih;
    memset( &bih, 0, sizeof( bih ) );
    bih.biSize = sizeof( bih );
   // bih.biWidth = lWidth;
   // bih.biHeight = lHeight;
    bih.biWidth = 281;     //自己硬写的
    bih.biHeight = 234;    //自己硬写的
    bih.biPlanes = 1;
    bih.biBitCount = 32;
    WriteFile( hf, &bih, sizeof( bih ), &dwWritten, NULL );
    // 写位图数据
    WriteFile( hf, pBuffer, lBufferSize, &dwWritten, NULL );
    CloseHandle( hf );
    return 0;
  }
BYTE * pBuffer:缓冲数据
long lBufferSize 数据长度上面这个函数可以把 缓冲数据保存为 .bmp 格式的图片
我想保存为 .png 格式那要怎么写啊?
谢谢!

解决方案 »

  1.   

    自己去学习png文件格式,或者使用CImage等可以直接保存png格式的方法
      

  2.   

    先把图象画到DC上,再用GDI+的函数直接保存VOID Example_SaveFile(HDC hdc)
    {
       Graphics graphics(hdc);
     
       // Create an Image object based on a PNG file.
       Image  image(L"Mosaic.png");   // Draw the image.
       graphics.DrawImage(&image, 10, 10);   // Construct a Graphics object based on the image.
       Graphics imageGraphics(&image);   // Alter the image.
       SolidBrush brush(Color(255, 0, 0, 255));
       imageGraphics.FillEllipse(&brush, 20, 30, 80, 50);   // Draw the altered image.
       graphics.DrawImage(&image, 200, 10);   // Save the altered image.
       CLSID pngClsid;
       GetEncoderClsid(L"image/png", &pngClsid);
       image.Save(L"Mosaic2.png", &pngClsid, NULL);
    }
      

  3.   

    去网上download一个CImage,里面各种格式转换都有,编译出来生成一个lib库,你再调用这个库就可以了