CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2005
    Posts
    18

    Smile loading raw image in a frame

    hello.. im currently working on some projects. I have this dialog box wherein i have a command button and a frame controls. if the button is clicked, u have to open the raw image and display it on the frame (IDC_DISPLAY).. can u please help me on how to do it..

  2. #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.

  3. #3
    Join Date
    Dec 2005
    Posts
    40

    Re: loading raw image in a frame

    Could u pls explain more about what does this example do?

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

    Re: loading raw image in a frame

    Quote Originally Posted by rodolphe
    Could u pls explain more about what does this example do?
    why you are bumbing an old thread?

    this sample load bmp file from disc using the ::LoadImage(..) api.

    then display the the raw bits using ::SetDIBitsToDevice(..).

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5
    Join Date
    Dec 2005
    Posts
    40

    Re: loading raw image in a frame

    After using the Loadimage and sure using a BITMAP variable (let's say bitmap), we know that bitmap.bmbits returns a Pointer to the location of the bit values for the bitmap. How would it possible to access to the memory content pointed by this pointer in order to read the "values" of the bitmap??

  6. #6
    Join Date
    May 2005
    Posts
    4,954

    Re: loading raw image in a frame

    Quote Originally Posted by rodolphe
    After using the Loadimage and sure using a BITMAP variable (let's say bitmap), we know that bitmap.bmbits returns a Pointer to the location of the bit values for the bitmap. How would it possible to access to the memory content pointed by this pointer in order to read the "values" of the bitmap??
    in this thread you created ( Device Context,DIB,DDB ) look at my first post there i gave you link to a thread LoadImage() which shows how load image from file and get the image raw bits.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  7. #7
    Join Date
    Dec 2005
    Posts
    40

    Re: loading raw image in a frame

    golanshahar: thanks. I agree with you, but how do we simply read the content for the "bitmap.bmbits" pointer?

    Note:


    bmBits
    Pointer to the location of the bit values for the bitmap. The bmBits member must be a long pointer to an array of character (1-byte) values.
    Last edited by rodolphe; December 21st, 2005 at 06:54 AM.

  8. #8
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: loading raw image in a frame

    Add the follwing code with ur button click function
    Code:
    	CString szFilename ("c:\\1.bmp");
    	HBITMAP hBmp = (HBITMAP)::LoadImage(
    						0,
    						szFilename,
    						IMAGE_BITMAP,
    						0,
    						0,
    						LR_LOADFROMFILE|LR_CREATEDIBSECTION
    						);
    	CDC *pDC;				
    	pDC=GetDC();
    	CBitmap     bmpHello;
        bmpHello.Attach(hBmp); 
        BITMAP bm;
        bmpHello.GetObject( sizeof(BITMAP), &bm );
        CDC         dcMem;
        dcMem.CreateCompatibleDC( pDC );
        CBitmap* pbmpOld = dcMem.SelectObject( &bmpHello );
        pDC->BitBlt( 30,50, bm.bmWidth, bm.bmHeight,&dcMem, 0,0, SRCCOPY );
        dcMem.SelectObject( pbmpOld );
        ReleaseDC( pDC );
    If I Helped You, "Rate This Post"

    Thanks
    Guna

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