#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    9
    Rep Power
    0

    C++ (Load then paint Image data )


    What is the simplest way in c++ to load image data in RGBA format and "paint" it on a Windows Device Context . I know you would have to use CImage in some way for this. But how?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    You might have better luck asking a windows programming question on a windows programming forum.
  4. #3
  5. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    This works only with bitmaps (as windows uses bitmaps unless you go to GDI++ or a third party lib)

    It is a NOT the best way (by a long way) and will NOT produce speedy flicker free updates.

    you should also use a frame buffer but...........

    This is some MFC C++, let me know if you prefer WIN32 C

    Code:
    //load image from file to member var ( a HBITMAP )
    sprintf(m_sImage, ".\\Images\\AnImage.bmp" ); // set the images full path from file
    	m_hImage = (HBITMAP) LoadImage( hInstance, m_sImage, IMAGE_BITMAP ,0 ,0 ,LR_LOADFROMFILE );
    
    // find size of image
    BITMAP	BMP;
    GetObject( m_hImage ,sizeof( BITMAP ), &BMP);
    
    //in OnPaint()
    CPaintDC		dc(this); // device context for painting
    
    //we need something to draw from
    //create a compatible DC and select our image into it
    DC.CreateCompatibleDC( &dc );// create DC compat to screen 
    HBITMAP	hOld = (HBITMAP) DC.SelectObject( m_hImage );// catch the current bitmap
    //draw to the screen DC
    dc.BitBlt( 0, 0, BMP.bmWidth, BMP.bmHeight, &DC ,0 ,0 ,SRCCOPY);
    DC.SelectObject( hOld);// put the old back
    DC.DeleteDC(); // delete what we created
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    9
    Rep Power
    0
    I have access to third party software. Will this ease the task. If so can you show me how to use either the W2K gdiplus AlphaBlend function and/or the MFC/ATL CImage object. Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo