Ja, aber wie ich habe jetzt doch nur einen printdlg. wie kann ich diesem mein bild übergeben?
Announcement
Collapse
No announcement yet.
png drucken
Collapse
X
-
Der Dialog stellt nur die Parameter bereit
http://www.google.de/search?q=mfc+bi...-a&safe=activeChristian
Comment
-
Habe jetzt folgendes getestet:
Code:// Extract the bitmap from the View window CDC* ViewDC = m_View.GetDC(); CDC MemDC = CreateCompatibleDC((HDC)ViewDC); MemDC.CreateCompatibleBitmap(ViewDC, mWindow->getWidth(), mWindow->getHeight()); BitBlt((HDC)MemDC, 0, 0, mWindow->getWidth(), mWindow->getHeight(), (HDC)ViewDC, 0, 0, SRCCOPY); HBITMAP hbmView = MemDC.DetachBitmap(); // Bring up a dialog to choose the printer PRINTDLG pd = {0}; pd.lStructSize = sizeof( pd ); pd.Flags = PD_RETURNDC; // Retrieve the printer DC if (PrintDlg( &pd )) { // Zero and then initialize the members of a DOCINFO structure. DOCINFO di = {0}; di.cbSize = sizeof(DOCINFO); di.lpszDocName = ("Scribble Printout"); di.lpszOutput = (LPTSTR) NULL; di.lpszDatatype = (LPTSTR) NULL; di.fwType = 0; // Begin a print job by calling the StartDoc function. StartDoc(pd.hDC, &di); // Inform the driver that the application is about to begin sending data. StartPage(pd.hDC); int Width = mWindow->getWidth(); int Height = mWindow->getHeight(); // Fill the BITMAPINFOHEADER structure BITMAPINFOHEADER bi = {0}; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biHeight = Height; bi.biWidth = Width; bi.biPlanes = 1; bi.biBitCount = 24; bi.biCompression = BI_RGB; // Note: BITMAPINFO and BITMAPINFOHEADER are the same for 24 bit bitmaps // Get the size of the image data GetDIBits(MemDC, hbmView, 0, Height, NULL, (BITMAPINFO*)&bi, DIB_RGB_COLORS); // Retrieve the image data byte* pBits = new byte[bi.biSizeImage]; GetDIBits(MemDC, hbmView, 0, Height, pBits, (BITMAPINFO*)&bi, DIB_RGB_COLORS); // Determine the scaling factors required retain the bitmap's original proportions. float fLogPelsX1 = (float) GetDeviceCaps((HDC)ViewDC, LOGPIXELSX); float fLogPelsY1 = (float) GetDeviceCaps((HDC)ViewDC, LOGPIXELSY); float fLogPelsX2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSX); float fLogPelsY2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSY); float fScaleX = max(fLogPelsX1, fLogPelsX2) / min(fLogPelsX1, fLogPelsX2); float fScaleY = max(fLogPelsY1, fLogPelsY2) / min(fLogPelsY1, fLogPelsY2); // Compute the coordinates of the upper left corner of the centered bitmap. int cWidthPels = GetDeviceCaps(pd.hDC, HORZRES); int xLeft = ((cWidthPels / 2) - ((int) (((float) Width) * fScaleX)) / 2); int cHeightPels = GetDeviceCaps(pd.hDC, VERTRES); int yTop = ((cHeightPels / 2) - ((int) (((float) Height) * fScaleY)) / 2); // Use StretchDIBits to scale the bitmap and maintain its original proportions StretchDIBits(pd.hDC, xLeft, yTop, (int) ((float) Width * fScaleX), (int) ((float) Height * fScaleY), 0, 0, Width, Height, pBits, (BITMAPINFO*)&bi, DIB_RGB_COLORS, SRCCOPY); // Inform the driver that the page is finished. EndPage(pd.hDC); // Inform the driver that document has ended. EndDoc(pd.hDC); // Cleanup ::DeleteObject(hbmView); delete []pBits; }
Code:// Use StretchDIBits to scale the bitmap and maintain its original proportions StretchDIBits(pd.hDC, xLeft, yTop, (int) ((float) Width * fScaleX), (int) ((float) Height * fScaleY), 0, 0, Width, Height, pBits, (BITMAPINFO*)&bi, DIB_RGB_COLORS, SRCCOPY);
Comment
-
Habe herausgefunden, dass es hier hapern muss :
Code:CDC* ViewDC; Ogre::LogManager::getSingletonPtr()->logMessage("######################### TEST1"); ViewDC->SelectObject(newBitMap); Ogre::LogManager::getSingletonPtr()->logMessage("######################### TEST2"); CDC MemDC = CreateCompatibleDC((HDC)ViewDC); MemDC.CreateCompatibleBitmap(ViewDC, mWindow->getWidth(), mWindow->getHeight()); BitBlt((HDC)MemDC, 0, 0, mWindow->getWidth(), mWindow->getHeight(), (HDC)ViewDC, 0, 0, SRCCOPY); HBITMAP hbmView = MemDC.DetachBitmap();
Comment
-
Oh sorry, ich habe ja getestet. hier der aktuelle Code:
Code:CBitmap* newBitMap; newBitMap->CreateCompatibleBitmap CreateBitmap(texture->getWidth(), texture->getHeight(), 1, 24, readrefdata); readbuffer->unlock(); // Extract the bitmap from the View window CDC* ViewDC; Ogre::LogManager::getSingletonPtr()->logMessage("######################### TEST1"); ViewDC->SelectObject(newBitMap); Ogre::LogManager::getSingletonPtr()->logMessage("######################### TEST2"); CDC MemDC = CreateCompatibleDC((HDC)ViewDC); MemDC.CreateCompatibleBitmap(ViewDC, mWindow->getWidth(), mWindow->getHeight()); BitBlt((HDC)MemDC, 0, 0, mWindow->getWidth(), mWindow->getHeight(), (HDC)ViewDC, 0, 0, SRCCOPY); HBITMAP hbmView = MemDC.DetachBitmap();
Comment
Comment