BitBlt i drukowanie obrazu

0

Witam znalazłem gdzieś taki kod dzięki któremu można wysłać polecenie wydrukowania textu, tylko zależy mi jeszcze żeby można było wydrukować obraz; Próbowałem to zrealizować z użyciem funkcji bitblt ale coś mi nie wychodziło. co i jak trzeba dodać jeszcze do tego kodu żeby można było wydrukować bitmape?
Za pomoc z góry dzięki.

 #include <windows.h>
int main(){
HDC hdcPrint;               // printer DC handle 
    char szDevString[120];      // array for WIN.INI data 
    char *szPrinter, *szDriver; // printer and driver names 
    char *szPort;               // port name 
 
    // Retrieve the printer, printer-driver, and 
    // output-port names from WIN.INI. 
 
    GetProfileString("windows", "device", ",,,", 
        szDevString, 120); 
 
    // Parse the string of names, setting ptrs as required 
    // If the string contains the required names, use them to 
    // create a device context. 
 
    if ((szPrinter = strtok(szDevString, 
               (const char *) ",")) 
            && (szDriver = strtok ((char *) NULL, 
               (const char *) ", ")) 
            && (szPort = strtok ((char *) NULL, 
               (const char *) ", "))) 
    {
        hdcPrint = CreateDC(szDriver, szPrinter, 
            szPort, NULL); 
    }
 
    // Print a test page that contains the string 
    // "PRINTER TEST" in the upper left corner. 
 
    Escape(hdcPrint, STARTDOC, 8, "Test-Doc", NULL); 
    TextOut(hdcPrint, 50, 50, "PRINTER TEST", 12); 
    Escape(hdcPrint, NEWFRAME, 0, NULL, NULL); 
    Escape(hdcPrint, ENDDOC, 0, NULL, NULL); 
 
 
    // Delete the printer DC. 
 
    DeleteDC(hdcPrint); 
 return 0;
}
0

Ja w jakimś programie rozwiązałem to tak:

HDC hdc, hdcimage;
PAINTSTRUCT p;
HBITMAP trip;
BITMAP info_trip;
trip = (HBITMAP)LoadImage(0,sciezka_trip.c_str(),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
GetObject(trip,sizeof(BITMAP),&info_trip);
hdc=BeginPaint(hwnd2,&p);
hdcimage=CreateCompatibleDC(hdc);
SelectObject(hdcimage,trip);
BitBlt(hdc,0,0,info_trip.bmWidth,info_trip.bmHeight,hdcimage,0,0,SRCCOPY);
DeleteDC(hdc);
DeleteDC(hdcimage);
EndPaint(hwnd2,&p);

Może Ci się przyda.

0

Ok, rozwiązałem problem; drukuje wybrany obraz, co prawda rozmiar jest bardzo mały i niezgodny z rzeczywistym, ale chyba da się to jakoś ustawić ten rozmiar (mam nadzieję). Jak mi się uda to naniosę poprawkę.
Uzupełniony kod niżej. Chyba że ktoś wie jak ustawić rozmiar obrazu, to prosił bym o odpowiedź.

 
#include <windows.h>
int main(){
HDC hdcPrint;               // printer DC handle 
    char szDevString[120];      // array for WIN.INI data 
    char *szPrinter, *szDriver; // printer and driver names 
    char *szPort;               // port name 
 
    // Retrieve the printer, printer-driver, and 
    // output-port names from WIN.INI. 
 
    GetProfileString("windows", "device", ",,,", 
        szDevString, 120); 
 
    // Parse the string of names, setting ptrs as required 
    // If the string contains the required names, use them to 
    // create a device context. 
 
    if ((szPrinter = strtok(szDevString, 
               (const char *) ",")) 
            && (szDriver = strtok ((char *) NULL, 
               (const char *) ", ")) 
            && (szPort = strtok ((char *) NULL, 
               (const char *) ", "))) 
    {
        hdcPrint = CreateDC(szDriver, szPrinter, 
            szPort, NULL); 
    }
 
    // Print a test page that contains the string 
    // "PRINTER TEST" in the upper left corner. 

HDC hdc, hdcimage;
PAINTSTRUCT p;
HBITMAP trip;
BITMAP info_trip;
trip = (HBITMAP)LoadImage(0,"C:/sc2.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
GetObject(trip,sizeof(BITMAP),&info_trip);
hdc=BeginPaint(0,&p);
hdcimage=CreateCompatibleDC(hdc);
SelectObject(hdcimage,trip);

Escape(hdcPrint, STARTDOC, 8, "Test-Doc", NULL); 
TextOut(hdcPrint, 50, 50, "PRINTER TEST", 12); 
BitBlt(hdcPrint,0,0,info_trip.bmWidth,info_trip.bmHeight,hdcimage,0,0,SRCCOPY);
    Escape(hdcPrint, NEWFRAME, 0, NULL, NULL); 
    Escape(hdcPrint, ENDDOC, 0, NULL, NULL); 
 
 
    // Delete the printer DC. 
 
    DeleteDC(hdcPrint); 
    EndPaint(0,&p);
 DeleteDC(hdc);
DeleteDC(hdcimage);

 return 0;
}

0
info_trip.bmWidth,info_trip.bmHeight

Dziwna sprawa. Tu trzymany jest rozmiar bitmapy. Spróbuj wpisać wymiary na sztywno.

0

Dobra to też również rozwiązałem, zamiast funkcji bitblt wstawiamy
StretchBlt(hdcPrint,0,0,ROZMIAR_WYDRUKU_OŚX,ROZMIAR_WYDRUKU_OŚY,hdcimage,0,0,info_trip.bmWidth,info_trip.bmHeight,SRCCOPY);

0

Jeszcze by mi się przydało wiedzieć jak można utworzyć okno dialogowe z wyborem drukarki liczby kopii itp. i zintegrować to z powyższym kodem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1