HBITMAP verkleinern und Tranparent darstellen



  • Hallo,

    wie die Überschrift schon sagt möchte ich das Bild verkleinert und mithilfe eines Colorkeys ohne Ränder darstellen. Das Bild ist Korrekt geladen und lässt sich auch darstellen (mit BitBlt). Bisher habe ich Folgendes:

    void BltImage(const HBITMAP bmp, HDC hdc, int x, int y, int xsize, int ysize)
    {
    	BITMAP bm;
    	GetObject((HANDLE)bmp, sizeof(bm), static_cast<void *>(&bm));
    	x -= xsize / 2; // (x/y( gibt die Mitte des Bildes an
    	y -= ysize / 2;
    	HDC temp = CreateCompatibleDC(hdc);
    	HDC temp2 = CreateCompatibleDC(hdc);
    	SelectObject(temp, bmp);
    
    	StretchBlt(temp2, 0, 0, xsize, ysize, temp, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
    	TransparentBlt(hdc, x, y, xsize, ysize, temp2, 0, 0, xsize, ysize, RGB(0, 0, 0));
    
    	DeleteDC(temp);
    	DeleteDC(temp2);
    }
    

    wenn ich eine der Beiden Zeilen auskommentiere funktioniert alles wie es soll, d.h. ich kann enweder verkleinern oder Transparent darstellen. Es soll aber beides 🙂

    Wie bekomme ich das hin ?

    mfg Helferlein



  • void BltImage(const HBITMAP bmp, HDC hdc, int x, int y, int xsize, int ysize)
    {
    	BITMAP bm;
    	GetObject((HANDLE)bmp, sizeof(bm), static_cast<void *>(&bm));
    	x -= xsize / 2;
    	y -= ysize / 2;
    	HDC temp = CreateCompatibleDC(hdc);
    	HDC temp2 = CreateCompatibleDC(hdc);
    	HBITMAP bmp2 = CreateCompatibleBitmap(hdc, xsize, ysize);
    	SelectObject(temp, bmp);
    	SelectObject(temp2, bmp2);
    
    	StretchBlt(temp2, 0, 0, xsize, ysize, temp, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
    	TransparentBlt(hdc, x, y, xsize, ysize, temp2, 0, 0, xsize, ysize, RGB(0, 0, 0));
    
    	DeleteObject(bmp2);
    	DeleteDC(temp);
    	DeleteDC(temp2);
    }
    

    😃


Anmelden zum Antworten