GetBimapBits



  • Bei der Klasse CBitmap, gibt es die Member GetBitmapBits, und SetBitmapBits.
    In einer Beschreibung habe ich gelesen, dass diese Funktionen nur beschränkt
    nutzbar seien, weil es unterschiedliche Formate gibt ( png ... ). Kann man diese
    Formate irgendwie einsehen. Im Internet auf welchen Seiten ? Sind da nicht in
    allen Formaten die Farb-Bytes nacheinander gespeichert Rot, Grün, Blau ?



  • Note: This function is provided only for compatibility with 16-bit versions of Windows.
    https://msdn.microsoft.com/de-de/library/windows/desktop/dd144850.aspx

    Alternative lt. MSDN: GetDIBits function



  • Hi,

    es gibt Depends und independs Bitmaps, also Bitmaps die compatible zur
    aktuellen Auflösung sind oder nicht, dies betrifft die Bittiefe.

    Um diese Formate alle samt gleich über die Hardware auf einen gleichnamigen
    Zugriff zu bringen, solltest Du DibSectionen verwenden.

    Einmal hersgetsllt steht diese als Hardware gestützte Wunschschablone zur Verfügung. Du kannst eine 2 Bit Grafik hier rein blitten: Zb. BlitDib SetDibsToDevice u.a.

    Danach befinden sich in dem für die DibSection bereitgestellten linearen Ziel -Speicher die Bildpunkte in dem erwünschten Format zum ansprechen über pointer zur Verfügung. Gefüllt wird dieser Speicher über Blit Operationen auf DibSectionen, diese aktionen dauern weniger als 1ms und werden durch die Hal (Hardwareabstarktionslayer) vollkommen an der CPU vorbei konvertiert.

    Pseudo Code

    m_hdd[0]  = DrawDibOpen();
    
    bool CDib::Create(int Width, int Height, int Bpp/*=32*/,int board/*=0*/,int port/*=0*/,int NumBuffs/*=1*/)
    {
    	CDib::Delete();
    
    	if(!m_hdd[0] || !m_hdd[1])
          return  CVersions::DbgMsg(false,"error: Dib:Create:DibOpen\n");
    
    	if (!AllocBitmapInfo(&m_pBitmapInfo, Width, -Height, Bpp))
    	 return CVersions::DbgMsg(false, "error: Dib:Create:AllocBitmapInfo\n");
    
    	m_Height = abs(Height);
    	m_Width  = Width;
    	m_Bpp    = Bpp;
    
    	if(!(m_hDC = CreateCompatibleDC(0)))
        {
    	  Delete();
    	  return  CVersions::DbgMsg(false,"error: Dib:Create:CreateCompatibleDC\n");
        }
    
    	GdiFlush();//see documentation
    
        m_hBmp = CreateDIBSection(m_hDC, m_pBitmapInfo, DIB_RGB_COLORS, (void**)&m_pDat, NULL, NULL);	
    	if(!m_hBmp)
        {
    	  Delete();
    	  return  CVersions::DbgMsg(false,"Dib:Create:DIBSection error W(%d) H(%d) BPP(%d)\n",Width,Height,Bpp);
        }
    
    	m_hOldBitmap = (HBITMAP)SelectObject (m_hDC, m_hBmp);// Select hBitmap Into Our Device Context (hdc)
    
    	return true;
    }
    
    bool CDib::AllocBitmapInfo(BITMAPINFO **ppBitmapInfo, int Width, int Height, int Bpp)
    {
    	*ppBitmapInfo = (BITMAPINFO*)(new char[sizeof(BITMAPINFOHEADER) + ((Bpp == 8 ? 256 : 1)*sizeof(RGBQUAD))]);
    
    	if (!*ppBitmapInfo)
    		return FALSE;
    
    	(*ppBitmapInfo)->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    	(*ppBitmapInfo)->bmiHeader.biWidth = Width;
    	(*ppBitmapInfo)->bmiHeader.biHeight = Height;//Bpp==8|Bpp==24?-Height:Height;//botomup
    	(*ppBitmapInfo)->bmiHeader.biPlanes = 1;
    	(*ppBitmapInfo)->bmiHeader.biBitCount = Bpp;
    	(*ppBitmapInfo)->bmiHeader.biCompression = BI_RGB;
    	(*ppBitmapInfo)->bmiHeader.biSizeImage = Width*abs(Height)*(Bpp >> 3);
    	(*ppBitmapInfo)->bmiHeader.biXPelsPerMeter = 0;
    	(*ppBitmapInfo)->bmiHeader.biYPelsPerMeter = 0;
    	(*ppBitmapInfo)->bmiHeader.biClrUsed = Bpp == 8 ? 256 : 0;
    	(*ppBitmapInfo)->bmiHeader.biClrImportant = 0;
    
    	if ((*ppBitmapInfo)->bmiHeader.biClrUsed)
    		SetColorbasis(*ppBitmapInfo, RGB(255, 255, 255), 1);
    
    	return true;
    }
    
    BOOL CDib::Draw(HDC hdc,void *pMem,CRect rc,int xSrcOffset,int ySrcOffset,int xDstOffset,int yDstOffset)
    {	
      if(!m_pBitmapInfo)
    	return FALSE;
    
      if(!pMem)
       pMem = m_pDat;
    
      ::SetDIBitsToDevice(hdc,    
    	            rc.left+xDstOffset,
    				rc.top+yDstOffset,
    				rc.Width(),
    				rc.Height(),
    				rc.left+xSrcOffset,                            //SrcX
    				abs(m_pBitmapInfo->bmiHeader.biHeight) - (rc.top+ySrcOffset) - rc.Height(),  //SrcY
    				0,                         
    				abs(m_pBitmapInfo->bmiHeader.biHeight),             
    				(void *)pMem,
    				m_pBitmapInfo,
    				DIB_RGB_COLORS//DIB_PAL_COLORS  
    				);
    
      return TRUE;
    }
    

    Der Speicher Inhalt ist nun über den MemoryPointer m_pDat erreichbar, einfach etwas rein blitten ...

    Gruß
    Karsten


Anmelden zum Antworten