下面是C#的
//Bitmap转byte[]  
        public static byte[] BitmapToBytes(Bitmap Bitmap) 
        {             MemoryStream ms = null; 
            try 
            { 
                ms = new MemoryStream(); //这个好象是NET的类,但我用MFC
                Bitmap.Save(ms, Bitmap.RawFormat); //这是啥?
                byte[] byteImage = new Byte[ms.Length]; //这是啥
                byteImage = ms.ToArray();//这是啥 
                return byteImage; 
            } 

解决方案 »

  1.   

      byteImage = ms.ToArray();//这是啥 】Writes the stream contents to a byte array, regardless of the Position property.
      

  2.   

    http://www.mysjtu.com/page/M0/S685/685366.html
      

  3.   

    点击太快了  sorry 看错了!
      

  4.   

    #include "stdafx.h"
    #include <atlimage.h>
    #include <assert.h>
    #include <stdio.h>int _tmain(int argc, _TCHAR* argv[])
    {
      CImage image;
      HRESULT hr;
      // Load sample image
      hr = image.Load(L"c:\\temp\\test.bmp");
      assert(hr == S_OK);  // Calculate reasonably safe buffer size
      int stride = 4 * ((image.GetWidth() + 3) / 4);
      size_t safeSize = stride * image.GetHeight() * 4 + sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER) + 256 * sizeof(RGBQUAD);
      HGLOBAL mem = GlobalAlloc(GHND, safeSize);
      assert(mem);  // Create stream and save bitmap
      IStream* stream = 0;
      hr = CreateStreamOnHGlobal(mem, TRUE, &stream);
      assert(hr == S_OK);
      hr = image.Save(stream, Gdiplus::ImageFormatBMP);
      assert(hr == S_OK);  // Allocate buffer for saved image
      LARGE_INTEGER seekPos = {0};
      ULARGE_INTEGER imageSize;
      hr = stream->Seek(seekPos, STREAM_SEEK_CUR, &imageSize);
      assert(hr == S_OK && imageSize.HighPart == 0);
      BYTE* buffer = new BYTE[imageSize.LowPart];  // Fill buffer from stream
      hr = stream->Seek(seekPos, STREAM_SEEK_SET, 0);
      assert(hr == S_OK);
      hr = stream->Read(buffer, imageSize.LowPart, 0);
      assert(hr == S_OK);  // Save to disk
      FILE* fp = 0;
      errno_t err = _wfopen_s(&fp, L"c:\\temp\\copy.bmp", L"wb");
      assert(err == 0 && fp != 0);
      fwrite(buffer, 1, imageSize.LowPart, fp);
      fclose(fp);  // Cleanup
      stream->Release();
      delete[] buffer;
      return 0;
    }
      

  5.   

    cimage是载入 bmp图片的 可以使用cbitmap载入然后转成bitmap
    CBitmap 转 Bitmap:
    Bitmap m_pBackBmp = ::new Bitmap((HBITMAP)::GetCurrentObject(CurDC, OBJ_BITMAP),NULL);
      

  6.   

    那不就内存泄露 么用完了delete掉!
      

  7.   

     
    而且我保存的时候是和截屏,并没有保存到客户区里所画的图象Bitmap* m_pBackBmp = ::new Bitmap((HBITMAP)::GetCurrentObject(GetDC()->GetSafeHdc(), OBJ_BITMAP),NULL);
    CLSID Clsid;
    GetEncoderClsid(_T("image/jpg"), &Clsid);
    m_pBackBmp->Save(_T("001.jpg"),&Clsid,NULL);
      

  8.   

    这都不是重点,再次回到标题的问题Bitmap*转byte[] 用MFC怎么写!