CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: loading raw image in a frame

    here use my function here:
    Code:
    // hwnd    = handle to the image control
    // W    = width of the raw bits Image
    // H    = height of the raw bits Image
    // lpBits  = pointer to the raw bits image
    // BitCount = 32,24 etc ( depend on the bit count ) defualt =32
    void SetRawBitsToImage (HWND hwnd,int W,int H,BYTE *lpBits, int BitCount =32 )
    {
      HDC  hDC = ::GetDC(hwnd);
      ::SetWindowPos(hwnd,0,0,0,W,H,SWP_NOMOVE);
    
      BITMAPINFO bi;
      memset(&bi,0,sizeof(BITMAPINFO));
      bi.bmiHeader.biSize      = sizeof(BITMAPINFOHEADER);
      bi.bmiHeader.biWidth    = W;
      bi.bmiHeader.biHeight    = H;
      bi.bmiHeader.biPlanes    = 1;
      bi.bmiHeader.biBitCount    = BitCount;
      bi.bmiHeader.biCompression  = BI_RGB;
      bi.bmiHeader.biSizeImage  = bi.bmiHeader.biWidth*bi.bmiHeader.biHeight*BitCount/8; 
    
      
      ::SetDIBitsToDevice(hDC,
                    0,0,
                    W,
                    H,
                    0,
                    0,
                    0,bi.bmiHeader.biHeight,
                    lpBits,&bi,DIB_RGB_COLORS);
    
      ::ReleaseDC(hwnd,hDC);
    
    }
    now here is an example how you call it
    Code:
      HWND hImage   = this->GetDlgItem(IDC_S)->GetSafeHwnd();
                   BYTE *Image = new BYTE[100*100*4]; // empty image
      SetRawBitsToImage (hImage,100,100,Image ,32);
    now in my sample i just created garbaged image and i display it, you should provide the real image, i dont know if you have the bitmap raw bits you can get them by ::GetBitmapBits(..) api.
    and in order to load bitmap from disc use the ::LoadImage(..) api.

    hope its covers what you need.


    Cheers
    Last edited by golanshahar; October 7th, 2005 at 01:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured