ERLEDIGT
JA
JA
ANTWORTEN
2
2
ZUGRIFFE
1689
1689
EMPFEHLEN
-
Hallo,
ich will auf dem Desktop ein Bitmap zeichnen.
Das Problem ist jetzt, das ich nur die bitmap im Sinne des Wortes habe:
Also wirklich nur die map!Code :1
BYTE* bmp;
Den Header kann ich neu generieren, da ich die Parameter bereits weis.
Mein Code sieht bis jetzt so aus:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <iostream> using namespace std; //Hier habe ich ein 100x200 24bit BMP verwendet void drawBMP(BYTE* bmp) { HWND hWnd = GetDesktopWindow(); HDC hdc = GetDC(hWnd); HBITMAP hbm = CreateCompatibleBitmap(hdc, 100, 200); BITMAPINFO bmi; memset(&bmi, '\0', sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = 100; bmi.bmiHeader.biHeight = 200; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 24 * 100 * 200 / 8; cout << SetDIBits( hdc, hbm, 0, bmi.bmiHeader.biHeight, bmp, &bmi, DIB_RGB_COLORS ); ReleaseDC(hWnd,hdc); DeleteObject(hbm); }
Die Ausgabe ist 200, also müsste es doch geklappt haben.
Die übergebenen daten sind richtig, denn der Bitmap lässt sich pixelweise damit zeichen, was aber leider zu langsam ist.
Ich habe so das Gefühl das alles grundlegend falsch ist...
Bitte um Hilfe!
-
Hab jetzt einen weiteren Ansatz:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
void drawBMP(BYTE* bmp) { HWND hWnd = GetDesktopWindow(); HDC hdc = GetDC(hWnd); HDC memDC = CreateCompatibleDC(hdc); HBITMAP hbm = CreateCompatibleBitmap(hdc, 100, 200); HBITMAP hbmOld = (HBITMAP)SelectObject(memDC, hbm); BITMAPINFO bmi; memset(&bmi, '\0', sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = 100; bmi.bmiHeader.biHeight = 200; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biBitCount * 100 * 200 / 8; SetDIBits( memDC, hbm, 0, bmi.bmiHeader.biHeight, bmp, &bmi, DIB_RGB_COLORS ); BitBlt(hdc, 0, 0, 100, 200, memDC, 0, 0, SRCCOPY); SelectObject(memDC, hbmOld); DeleteDC(memDC); ReleaseDC(hWnd,hdc); DeleteObject(hbm); }
Das scheint mir mehr sinn zu ergeben. Funktioniert aber genauso wenig. Irgendwie blicke ich da nicht durch!
-
Ok es geht jetzt einigermaßen:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
void drawBMP(BYTE* bmp, int nBit, int width, int height) { HBITMAP hbm = CreateCompatibleBitmap(hdc, width, height); HDC hdcBitmap = CreateCompatibleDC( hdc ); HBITMAP hbmOld = (HBITMAP)SelectObject( hdcBitmap, hbm ); BITMAPINFO bmi; memset(&bmi, '\0', sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = height; bmi.bmiHeader.biBitCount = nBit; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biBitCount * width * height / 8; if (nBit == 1) { bmi.bmiHeader.biSizeImage = (bmi.bmiHeader.biBitCount+1) * width * height / 8; } else { bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biBitCount * width * height / 8; } SetDIBits( hdcBitmap, hbm, 0, bmi.bmiHeader.biHeight, bmp, &bmi, DIB_RGB_COLORS ); BitBlt(hdc, 0, 0, width, height, hdcBitmap, 0, 0, SRCCOPY); DeleteObject(hbm); SelectObject( hdcBitmap, hbmOld ); DeleteDC( hdcBitmap ); }
Ähnliche Themen
-
MFC SDI | Per GDI in Bitmap zeichnen?
Von eurostar123 im Forum VisualStudio & MFCAntworten: 1Letzter Beitrag: 08.03.10, 21:35 -
Bitmap auf MFC-Fenster zeichnen
Von Krankfried im Forum C/C++Antworten: 1Letzter Beitrag: 19.10.08, 21:23 -
Bitmap ausserhalb Bildschirm zeichnen (Textscroll)
Von WinDWalker im Forum C/C++Antworten: 1Letzter Beitrag: 19.10.05, 14:58 -
Auf Desktop zeichnen
Von James303 im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 28.06.05, 18:07 -
Auf Bitmap zeichnen
Von Mr_P1nk im Forum C/C++Antworten: 6Letzter Beitrag: 28.02.05, 09:24





Zitieren
Login






