Announcement

Collapse
No announcement yet.

png drucken

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Ja, aber wie ich habe jetzt doch nur einen printdlg. wie kann ich diesem mein bild übergeben?

    Comment


    • #17
      Der Dialog stellt nur die Parameter bereit
      http://www.google.de/search?q=mfc+bi...-a&safe=active
      Christian

      Comment


      • #18
        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;		
        			
        		}
        Hierbei habe ich dann gedacht, dass Bild nicht erst abzuspeichern, sondern gleich den aktuellen Bildschrim als Bild zu verwenden. Ich bekomme leider einen Error (bricht einfach ab) an der Stelle

        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);
        Kannst du mir da weiter helfen?

        Comment


        • #19
          Schon mal debuggt und die Parameter angesehen...
          Christian

          Comment


          • #20
            Hier
            Code:
             EndPage(pd.hDC);
            steht : pd.hDC unused, CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden.

            Weiß leider nicht was ich da machen könnte...

            Comment


            • #21
              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();
              Ich denke dass ViewDc->SelectObject(newBitMap) nicht funktioniert, weil diese Zeile nicht ausgeführt wird. (Test1 erhalte ich noch als Ausgabe, nciht aber Test2). Ist die Übergabe falsch oder was habe ich da verkehrt gemacht?

              Comment


              • #22
                Was soll man sagen? Die Zeile gibt es im obigen Code nicht und man kann nur raten, das newBitmap null sein könnte
                Christian

                Comment


                • #23
                  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();
                  Danach kommt dann der PrintDlg, an dem es jetzt erstmal nicht liegt, denke ich. newBitmap ist nciht null aber ViewDC.

                  Comment


                  • #24
                    ja, denn mit CDC* ViewDC; wird ja nur ein Zeige angelegt
                    Christian

                    Comment


                    • #25
                      Aber is ViewDC wird doch das newBitmap übergeben oder? (per selectobject()) oder habe ich das falsch verstanden?

                      Comment


                      • #26
                        Nein, ist korrekt...
                        Christian

                        Comment


                        • #27
                          Dann verstehe ich nicht warum

                          Code:
                          ViewDC->SelectObject(newBitMap);
                          nicht ausgeführt wird.

                          Comment


                          • #28
                            Kann mir niemand sagen, was da falsch läuft?

                            Comment

                            Working...
                            X