BitMap in CView zeichnen
-
Hi,
mein Document hat eine MemberVariable CBitmap Image.
Diese möchte ich nun in meiner View zeichnen.
Dies ist meine OnDraw(CDC* pDC):CILACCDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // Get the size of the bitmap BITMAP bmpInfo; pDoc->Image.GetBitmap(&bmpInfo); // Create an in-memory DC compatible with the // display DC we're using to paint CDC dcMemory; dcMemory.CreateCompatibleDC(pDC); // Select the bitmap into the in-memory DC dcMemory.SelectObject(&(pDoc->Image)); // Find a centerpoint for the bitmap in the client area CRect rect; GetClientRect(&rect); int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2; int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2; // Copy the bits from the in-memory DC into the on- // screen DC to actually do the painting. Use the centerpoint // we computed for the target offset. pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY);
Leider sehe ich nur weiß. Ich habe mir schon das Array pDoc->Image.GetBitmapBits(..) angeschaut und da scheint alles zu passen.
-
http://henkessoft.de/C++/MFC/mfc_einsteigerbuch_kapitel4.htm
http://henkessoft.de/C++/MFC/mfc_einsteigerbuch_kapitel9.htm
-
aber genau das was in Kapitel 4.3 beschrieben wird, mach ich doch:
Mein Document hat ein CBitmap Image und ein bool ImageInitialized als public member.
nach klick eines bestimmten Menüpunkts wird von einer angeschlossenen Kamera ein Bild gemacht, welches ich in BYTE* ImageBuf speicher. auserdem liefert sie mir die int ImageWidth und ImageHeight. anschließend ruf ich folgenden Code auf:ImageInitialized = Image.CreateBitmap(ImageWidth,ImageHeight,1,8,ImageBuf); POSITION Pos = GetFirstViewPosition(); CView* pView = GetNextView(Pos); pView->Invalidate();
Der einzige wirkliche Unterschied in der OnDraw-methode meiner View war, dass ich GetBitmap statt GetObject verwendet habe. Aber auch damit geht es nicht:
void MyProjectView::OnDraw(CDC* pDC) { MyProjectDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; if(!pDoc->ImageInitialized) return; BITMAP bmpInfo; //pDoc->Image.GetBitmap(&bmpInfo); pDoc->Image.GetObject(sizeof(bmpInfo),&bmpInfo); CDC dcMemory; dcMemory.CreateCompatibleDC(pDC); dcMemory.SelectObject(&(pDoc->Image)); pDC->BitBlt(0,0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY); }
-
Debuggen. Was steht in bmpInfo drin.
Keine Fehlerkontrolle.
-
ok, i solved it. The problem was, that 8-Bit Images don't seem to work, i had to convert to 32-Bit...