Esempio n. 1
0
// Bitmaps einlesen und Paletten initialisieren
bool CBildObjekt :: InitDIB (const char *pcFullName) 
{
int fh;					/* Dateihandle (evtl. komprimiertes File) */
OFSTRUCT of;            /* Dateistruktur */
HPALETTE hPalCurrent;   /* PaletteStruct */
HBITMAP hDIBCurrent;    /* DIB */
HBITMAP hBMCurrent;     /* DDB */

// alte DIB freigeben 
	FreeDIB ();

// Datei eröffnen, Speicherplatz anlegen
	fh = OpenFile (pcFullName, (OFSTRUCT *)&of, OF_READ);
	if (fh < 0) return false;

	hDIBCurrent = ReadDIBitmapInfo (fh);    // Farbtabelle lesen

// Gültigkeit der DIB-Datei prüfen 
	if (hDIBCurrent == NULL) {
		_lclose (fh);
		return false;
	}
	m_hDIB = hDIBCurrent;					// im Objekt merken

// PaletteSetup 
	hPalCurrent = CreateDIBPalette ();		// Palette bilden
	if (hPalCurrent == NULL) {
		_lclose (fh);
		return false;
	}
	m_hPal = hPalCurrent;

// DIB einlesen 
	hDIBCurrent = ReadDIB (fh);
	if (!hDIBCurrent) {
		_lclose (fh);
		return false;
	}
	m_hDIB = hDIBCurrent;
	_lclose (fh);

// DDB bilden
	hBMCurrent = DIBToBitmap();
	if (!hBMCurrent)
		return false;

	m_hDDB = hBMCurrent;

return true;
}
Esempio n. 2
0
QPixmap* QTwainInterface::convertToPixmap(CDIB* pDib)//,const unsigned int nWidth,const unsigned int nHeight)
{
    if (!pDib)
        return 0;

    unsigned int nUseWidth;
    unsigned int nUseHeight;

//	if (nUseWidth == 0)
    nUseWidth = pDib->Width();
//	if (nUseHeight == 0)
    nUseHeight = pDib->Height();

    //QPixmap* retval = new QPixmap(nUseWidth, nUseHeight);
    HANDLE hdib=pDib->DIBHandle();
    HPALETTE pepe =CreateDIBPalette(hdib);
    HBITMAP ima =DIBToBitmap(hdib,pepe);
    QPixmap* retval2= new QPixmap(QPixmap::fromWinHBITMAP ( ima,QPixmap::NoAlpha));

    //return retval2;
    //HDC hehe;

    /*pDib->BitBlt(hehe,
    	         0, 0,
    			 nUseWidth, nUseHeight,
    			 0, 0);
    			 QPixmap buffer(400, 200);
    ...
    bitBlt(&buffer, 0, 0, src, 0, 0, 400, 200);
    ...
    QPainter p(this);
    p.drawPixmap(0, 0, buffer);

    //HBITMAP ima =pDib->DIBToDDB(pdib);
    //QPixmap* retval2= new QPixmap(retval->fromWinHBITMAP ( ima,QPixmap::NoAlpha));
    */
    return retval2;
} // !convertToPixmap()
Esempio n. 3
0
HDIB ChangeDIBFormat(HDIB hDIB, WORD wBitCount, DWORD dwCompression)
{
    HDC                hDC;             // Handle to DC
    HBITMAP            hBitmap;         // Handle to bitmap
    BITMAP             Bitmap;          // BITMAP data structure
    BITMAPINFOHEADER   bi;              // Bitmap info header
    LPBITMAPINFOHEADER lpbi;            // Pointer to bitmap info
    HDIB               hNewDIB = NULL;  // Handle to new DIB
    HPALETTE           hPal, hOldPal;   // Handle to palette, prev pal
    WORD               DIBBPP, NewBPP;  // DIB bits per pixel, new bpp
    DWORD              DIBComp, NewComp;// DIB compression, new compression

    // Check for a valid DIB handle

    if (!hDIB)
        return NULL;

    // Get the old DIB's bits per pixel and compression format

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
    DIBBPP = ((LPBITMAPINFOHEADER)lpbi)->biBitCount;
    DIBComp = ((LPBITMAPINFOHEADER)lpbi)->biCompression;
    GlobalUnlock(hDIB);

    // Validate wBitCount and dwCompression
    // They must match correctly (i.e., BI_RLE4 and 4 BPP or
    // BI_RLE8 and 8BPP, etc.) or we return failure
    if (wBitCount == 0)
    {
        NewBPP = DIBBPP;
        if ((dwCompression == BI_RLE4 && NewBPP == 4) ||
                (dwCompression == BI_RLE8 && NewBPP == 8) ||
                (dwCompression == BI_RGB))
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 1 && dwCompression == BI_RGB)
    {
        NewBPP = wBitCount;
        NewComp = BI_RGB;
    }
    else if (wBitCount == 4)
    {
        NewBPP = wBitCount;
        if (dwCompression == BI_RGB || dwCompression == BI_RLE4)
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 8)
    {
        NewBPP = wBitCount;
        if (dwCompression == BI_RGB || dwCompression == BI_RLE8)
            NewComp = dwCompression;
        else
            return NULL;
    }
    else if (wBitCount == 24 && dwCompression == BI_RGB)
    {
        NewBPP = wBitCount;
        NewComp = BI_RGB;
    }
    else
        return NULL;

    // Save the old DIB's palette

    hPal = CreateDIBPalette(hDIB);
    if (!hPal)
        return NULL;

    // Convert old DIB to a bitmap

    hBitmap = DIBToBitmap(hDIB, hPal);
    if (!hBitmap)
    {
        DeleteObject(hPal);
        return NULL;
    }

    // Get info about the bitmap
    GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);

    // Fill in the BITMAPINFOHEADER appropriately

    bi.biSize               = sizeof(BITMAPINFOHEADER);
    bi.biWidth              = Bitmap.bmWidth;
    bi.biHeight             = Bitmap.bmHeight;
    bi.biPlanes             = 1;
    bi.biBitCount           = NewBPP;
    bi.biCompression        = NewComp;
    bi.biSizeImage          = 0;
    bi.biXPelsPerMeter      = 0;
    bi.biYPelsPerMeter      = 0;
    bi.biClrUsed            = 0;
    bi.biClrImportant       = 0;

    // Go allocate room for the new DIB

    hNewDIB = AllocRoomForDIB(bi, hBitmap);
    if (!hNewDIB)
        return NULL;

    // Get a pointer to the new DIB

    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hNewDIB);

    // Get a DC and select/realize our palette in it

    hDC  = GetDC(NULL);
    hOldPal = SelectPalette(hDC, hPal, FALSE);
    RealizePalette(hDC);

    // Call GetDIBits and get the new DIB bits

    if (!GetDIBits(hDC, hBitmap, 0, (UINT) lpbi->biHeight,
            (LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize((LPSTR)lpbi),
            (LPBITMAPINFO)lpbi, DIB_RGB_COLORS))
    {
        GlobalUnlock(hNewDIB);
        GlobalFree(hNewDIB);
        hNewDIB = NULL;
    }

    // Clean up and return

    SelectPalette(hDC, hOldPal, TRUE);
    RealizePalette(hDC);
    ReleaseDC(NULL, hDC);

    // Unlock the new DIB's memory block
    if (hNewDIB)
        GlobalUnlock(hNewDIB);

    DeleteObject(hBitmap);
    DeleteObject(hPal);

    return hNewDIB;
}