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

    24bit bitmap problem in other display modes

    Hello,
    can someone explain how i can get a 24bit bitmap
    to display in other display modes, my program
    opens a third party data file that stores some bitmaps
    in parts of it, the bitmap is stored as bgr raw data
    i read this data and flip the bytes to rgb, then use
    CreateBitmap(256,256,1,24,buf);
    everything works fine in my program as long as my display
    is set to 24bit color mode, any other mode i get a junk bitmap
    or nothing...

    i need a way to convert the bitmap to be compatible with
    the screen and still be able to save the 24bit data to save back to
    the file after modified

    hope you can help thanks,
    •SlimGradey•

  2. #2
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197

    Re: 24bit bitmap problem in other display modes

    What other modes are you trying to use?, 32 bit or lower modes and can you post an example rubbish bitmap display. It will help to understand what is happening.
    Requests such as
    "I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.

  3. #3
    Join Date
    May 2001
    Posts
    165

    Re: 24bit bitmap problem in other display modes

    this is how i read the bitmap
    Code:
    byte Raw_Data[196608];
    				
    memset(&Raw_Data,0xFF,sizeof(Raw_Data));
    
    f.Read(&Raw_Data,sizeof(Raw_Data));
    
    for(int i=0; i<196608; i+=3)
    {
    byte b = Raw_Data[i];
    byte g = Raw_Data[i+1];
    byte r = Raw_Data[i+2];
    Raw_Data[i] = r;
    Raw_Data[i+1] = g;
    Raw_Data[i+2] = b;
    }
    
    HBITMAP hBitmap = CreateBitmap(256,256,1,24,&Raw_Data);
    this works if my display is 24bit color i get a 256x256 image with
    the correct image displayed.
    if i have my display set to 16bit color or 256 color i get an image
    that contains some graphics from windows it contains the window icons
    the close button in different states like pressed,depressed...
    as long as my display is set to 24bit color everthing on my program works
    thanks for help,
    Attached Images Attached Images
    •SlimGradey•

  4. #4
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197

    Re: 24bit bitmap problem in other display modes

    So the icons are different as well or just the colours?
    Can you show how this bitmap is used when displaying?
    Requests such as
    "I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.

  5. #5
    Join Date
    May 2001
    Posts
    165

    Re: 24bit bitmap problem in other display modes

    this is what i use to show the bitmap,
    Code:
    	
    	if(m_Combo1.GetCount()>0)
    	{
    		int i = m_Combo1.GetCurSel();
    		
    		if(bm1 != NULL)
    			DeleteObject(bm1);
    
    		bm1 = CreateBitmapIndirect(m_BitmapArray.GetAt(i));
    		
    		CDC pDC;
    		pDC.CreateCompatibleDC(NULL);
    		HBITMAP old;
    		VERIFY(old = (HBITMAP)SelectObject(pDC.m_hDC,bm1));
    		
    		int sel = m_Combo2.GetCurSel();
    
    		int x = m_Texture_records.at(sel).X1;
    		int y = m_Texture_records.at(sel).Y1;
    		int w = m_Texture_records.at(sel).Width;
    		int h = m_Texture_records.at(sel).Height;
    		
    		CRect rect2;
    		rect2.top = y;
    		rect2.left = x;
    		rect2.right = w+x+1;
    		rect2.bottom = h+y+1;
    
    		if(m_Check1.GetCheck())
    		{
    			for(int i=0; i<256; i+=m_Down)
    			{
    				for(int a=0; a<256; a+=m_Across)
    				{
    					pDC.Draw3dRect(a,i,m_Across,m_Down,m_GridColor,m_GridColor);
    				}
    			}
    		}
    
    		pDC.Draw3dRect(&rect2,m_SelColor,m_SelColor);
    
    		SelectObject(pDC.m_hDC,old);
    		
    		m_Bitmap1.SetBitmap(bm1);
    
    		DeleteObject(old);
    		pDC.DeleteDC();
    		
    		m_strPages.Format("page %d of %d",i+1,m_Combo1.GetCount());
    
    		UpdateData(FALSE);
    
    	}

    i get a error in debug mode from the first SelectObject if i run in other than 24bit mode
    the image supose to look like the attached one below not the one with buttons
    thanks,
    Attached Images Attached Images
    •SlimGradey•

  6. #6
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197

    Re: 24bit bitmap problem in other display modes

    I suspec this call pDC.CreateCompatibleDC(NULL); is failing. Check the return from this call first.
    Requests such as
    "I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.

  7. #7
    Join Date
    May 2001
    Posts
    165

    Re: 24bit bitmap problem in other display modes

    hey Bob,
    i've done alot of test, everything returns successful,
    everything i tried points me to the CreateBitmap to be the problem
    i can load a 24bit bitmap and it will display properly in other modes,
    but the bitmap i create with CreateBitmap dosen't display properly
    if my display isn't set to 24bit color mode...
    i need to know of another function i can use to create an HBITMAP
    from an rgb buffer that will work in any display mode
    or another thing i can try is convert my rgb buffer from 24bit to 16bit
    is the user's display isn't 24bit but i don't know how it's formated
    i know 24bit is bgr 3 bytes each pixel but how's 16bit...

    thanks for help,
    •SlimGradey•

  8. #8
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197

    Re: 24bit bitmap problem in other display modes

    Requests such as
    "I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.

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