frisch kreierte DIBSection beim Blit schwarz..



  • Also ich hab ne DIBSection kreiert in die ich ein Bild legen will. Anschließend soll das Ganze geblittet werden.
    Nur bleibt bei mir der Screen schwarz:

    void blit (cImage *img, HDC hDC, int x, int y) {
    	BITMAPINFO bmi;
    	HBITMAP DIBSec;
    
    	ZeroMemory (&bmi, sizeof(bmi));
    	/* Create Bitmap Header */
    	bmi.bmiHeader.biSize		= sizeof(BITMAPINFOHEADER);
    	bmi.bmiHeader.biWidth 		= img->getWidth();
    	bmi.bmiHeader.biHeight 		= img->getHeight();
    	bmi.bmiHeader.biBitCount 	= img->getBPP() * 8;
    	bmi.bmiHeader.biPlanes 		= 1;
    	bmi.bmiHeader.biCompression = BI_RGB;
    	bmi.bmiHeader.biSizeImage 	= img->getBPP() * img->getWidth() * img->getHeight();
    
    	/* Create Bitmap */
    	unsigned char *lpdata = new unsigned char[bmi.bmiHeader.biSizeImage];
        DIBSec = CreateDIBSection( NULL, &bmi, DIB_RGB_COLORS, (void**)lpdata, NULL, 0);
        CopyMemory ((void*)lpdata, (const void*)img->getImage(), bmi.bmiHeader.biSizeImage);
    
    //	DIBSec = LoadBitmap (thisInstance, "grfx/test.bmp");
    	/* Blit Image */
        HDC     iDC = CreateCompatibleDC(hDC);
        SelectObject(iDC, DIBSec);
        BitBlt(hDC, x, y, img->getWidth(), img->getHeight(), iDC, 0, 0, SRCCOPY );
    
    	/* Cleanup */
        DeleteDC(iDC);
        DeleteObject (DIBSec);
        delete lpdata;
    }
    

    Hatte, wie man sieht, auch mal versucht, nen bitmap reinzuladen und das darzustellen.. da war dann nichtmal das schwarze Bild zu erkennen..

    mein Windows loop sieht so aus

    try {    
        cam = new cCam (hwnd);
        HDC hDC = GetDC(hwnd);
    
    	    /* Make the window visible on the screen */
    	    ShowWindow (hwnd, nFunsterStil);
    	    int done = 0;
    	    img = cam->getImage();
    
    	    load = loadBMPImage("grfx/test.bmp"); 
    
    	    /* Run the message loop. It will run until GetMessage() returns 0 */
    	    while (!done) {
    	        if (PeekMessage (&messages, NULL, 0, 0, PM_REMOVE)) {
    	            if (messages.message == WM_QUIT) {
    	                done = 1;
    	            } else {
    	                /* Translate virtual-key messages into character messages */
    	                TranslateMessage(&messages);
    	                /* Send message to WindowProcedure */
    	                DispatchMessage(&messages);
    	            }
    	        } else {
    	            blit(load, hDC, 320, 0);
    	            img = cam->getImage();
    	        }
    	    }
    	    ReleaseDC(hwnd, hDC);
    	} catch (char *e){
    		MessageBox (NULL, e, "Fehler", MB_OK);
    		PostQuitMessage(0);
    	}
    

    weiß zufällig wer, was ich korrigieren muss?

    cYa & thx
    DjR



  • Also ich bekomm das jetzt so weit hin.

    void blit (cImage *img, HDC hDC, int x, int y) {
    	BITMAPINFO bmi;
    	HBITMAP DIBSec;
    
    	unsigned char *lpdata = new unsigned char[bmi.bmiHeader.biSizeImage];
    	/* Create Bitmap Header */
    	ZeroMemory (&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
    	bmi.bmiHeader.biSize		= sizeof(BITMAPINFOHEADER);
    	bmi.bmiHeader.biWidth 		= img->getWidth();
    	bmi.bmiHeader.biHeight 		= img->getHeight();
    	bmi.bmiHeader.biPlanes 		= 1;
    	bmi.bmiHeader.biBitCount 	= img->getBPP() * 8;
    	bmi.bmiHeader.biSizeImage 	= img->getBPP() * img->getWidth() * img->getHeight();
    
    	/* Create Bitmap */
        DIBSec = CreateDIBSection( 0, &bmi, DIB_RGB_COLORS, (void**)lpdata, 0, 0);
        SetDIBits (0, DIBSec, 0, bmi.bmiHeader.biHeight, img->getImage(), &bmi, DIB_RGB_COLORS);
    
    	/* Blit Image */
        HDC     iDC = CreateCompatibleDC(hDC);
        SelectObject(iDC, DIBSec);
        BitBlt(hDC, x, y, img->getWidth(), img->getHeight(), iDC, 0, 0, SRCCOPY );
    
    	/* Cleanup */
        DeleteObject (DIBSec);
        ReleaseDC(0, iDC);
        delete lpdata;
    }
    

    Das SetDIBits macht scheinbar noch mehr als ein CopyMemory.

    Wie dem auch sei, jetzt hab ich doch einen interessanten Effekt.
    Ich nehme ein Bild mit einer Webcam auf und stelle es per blit (s.o.) dar.
    Das funktioniert super- solange die Maus nicht das Fenster berührt in dem das Ganze stattfindet..
    Woran kann sowas liegen?


Anmelden zum Antworten